-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: fields mapping refactor (#3595)
* Add .ruby-version file * chore: Set up Avo Meta * test: Write system test for happy path of creating a new schema entry * chore: Extract Avo::Mappings module with constants * chore: Reflect changes from avo-meta (look up field type) * chore: Test meta default values * chore: Test backfilling meta default values * wip * schema * lint --------- Co-authored-by: Julian Rubisch <[email protected]>
- Loading branch information
1 parent
3dfd9e7
commit 041d00f
Showing
4 changed files
with
118 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,4 @@ brakeman_results.html | |
|
||
.env | ||
.env.test | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
module Avo | ||
module Mappings | ||
unless defined?(ASSOCIATIONS_MAPPING) | ||
ASSOCIATIONS_MAPPING = { | ||
ActiveRecord::Reflection::BelongsToReflection => { | ||
field: "belongs_to" | ||
}, | ||
ActiveRecord::Reflection::HasOneReflection => { | ||
field: "has_one" | ||
}, | ||
ActiveRecord::Reflection::HasManyReflection => { | ||
field: "has_many" | ||
}, | ||
ActiveRecord::Reflection::HasAndBelongsToManyReflection => { | ||
field: "has_and_belongs_to_many" | ||
} | ||
}.freeze | ||
end | ||
|
||
unless defined?(ATTACHMENTS_MAPPING) | ||
ATTACHMENTS_MAPPING = { | ||
ActiveRecord::Reflection::HasOneReflection => { | ||
field: "file" | ||
}, | ||
ActiveRecord::Reflection::HasManyReflection => { | ||
field: "files" | ||
} | ||
}.freeze | ||
end | ||
|
||
unless defined?(FIELDS_MAPPING) | ||
FIELDS_MAPPING = { | ||
primary_key: { | ||
field: "id" | ||
}, | ||
string: { | ||
field: "text" | ||
}, | ||
text: { | ||
field: "textarea" | ||
}, | ||
integer: { | ||
field: "number" | ||
}, | ||
float: { | ||
field: "number" | ||
}, | ||
decimal: { | ||
field: "number" | ||
}, | ||
datetime: { | ||
field: "date_time" | ||
}, | ||
timestamp: { | ||
field: "date_time" | ||
}, | ||
time: { | ||
field: "date_time" | ||
}, | ||
date: { | ||
field: "date" | ||
}, | ||
binary: { | ||
field: "number" | ||
}, | ||
boolean: { | ||
field: "boolean" | ||
}, | ||
references: { | ||
field: "belongs_to" | ||
}, | ||
json: { | ||
field: "code" | ||
} | ||
}.freeze | ||
end | ||
|
||
unless defined?(NAMES_MAPPING) | ||
NAMES_MAPPING = { | ||
id: { | ||
field: "id" | ||
}, | ||
description: { | ||
field: "textarea" | ||
}, | ||
gravatar: { | ||
field: "gravatar" | ||
}, | ||
email: { | ||
field: "text" | ||
}, | ||
password: { | ||
field: "password" | ||
}, | ||
password_confirmation: { | ||
field: "password" | ||
}, | ||
stage: { | ||
field: "select" | ||
}, | ||
budget: { | ||
field: "currency" | ||
}, | ||
money: { | ||
field: "currency" | ||
}, | ||
country: { | ||
field: "country" | ||
} | ||
}.freeze | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters