module ActiveModelSerializers::Model::DeriveAttributesFromNamesAndFixAccessors
def self.included(base)
def self.included(base) # NOTE that +id+ will always be in +attributes+. base.attributes :id end
def attributes
+attributes+ are returned frozen to prevent any expectations that mutation affects
The the fields in +attribute_names+ determines the returned hash.
Override the +attributes+ method so that the hash is derived from +attribute_names+.
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