Module: ActiveModelSerializers::Model::DeriveAttributesFromNamesAndFixAccessors
- Defined in:
- lib/active_model_serializers/model.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes ⇒ Object
Override the
attributes
method so that the hash is derived fromattribute_names
.
Class Method Details
.included(base) ⇒ Object
57 58 59 60 |
# File 'lib/active_model_serializers/model.rb', line 57 def self.included(base) # NOTE that +id+ will always be in +attributes+. base.attributes :id end |
Instance Method Details
#attributes ⇒ Object
Override the attributes
method so that the hash is derived from attribute_names
.
The fields in attribute_names
determines the returned hash. attributes
are returned frozen to prevent any expectations that mutation affects the actual values in the model.
67 68 69 70 71 |
# File 'lib/active_model_serializers/model.rb', line 67 def attributes self.class.attribute_names.each_with_object({}) do |attribute_name, result| result[attribute_name] = public_send(attribute_name).freeze end.with_indifferent_access.freeze end |