Module: Caprese::Record::Aliasing::ClassMethods
- Defined in:
- lib/caprese/record/aliasing.rb
Instance Method Summary collapse
-
#caprese_alias_field(field) ⇒ Symbol
Given an actual field, convert to its appropriate field alias for the class.
-
#caprese_field_aliases ⇒ Object
Provides the ability to display an aliased field name to the consumer of the API, and then map that name to its real name on the server.
-
#caprese_type ⇒ Object
The type that is serialized and responded with for this class.
-
#caprese_unalias_field(field) ⇒ Symbol
Given an aliased field, convert to its actual field for the class.
Instance Method Details
#caprese_alias_field(field) ⇒ Symbol
The reason this is useful is because ActiveRecord validations must validate the actual field name of a model, but when we add errors they should always have aliased fields
Given an actual field, convert to its appropriate field alias for the class
30 31 32 |
# File 'lib/caprese/record/aliasing.rb', line 30 def caprese_alias_field(field) caprese_field_aliases.invert[field = field.to_sym] || field end |
#caprese_field_aliases ⇒ Object
Provides the ability to display an aliased field name to the consumer of the API, and then map that name to its real name on the server
48 49 50 |
# File 'lib/caprese/record/aliasing.rb', line 48 def caprese_field_aliases {} end |
#caprese_type ⇒ Object
The type that is serialized and responded with for this class
53 54 55 |
# File 'lib/caprese/record/aliasing.rb', line 53 def caprese_type self.name.underscore end |
#caprese_unalias_field(field) ⇒ Symbol
Given an aliased field, convert to its actual field for the class
38 39 40 |
# File 'lib/caprese/record/aliasing.rb', line 38 def caprese_unalias_field(field) caprese_field_aliases[field = field.to_sym] || field end |