Module: ActiveModel::Serializer::Attributes::ClassMethods
- Defined in:
- lib/active_model/serializer/concerns/attributes.rb
Instance Method Summary collapse
-
#_attributes ⇒ Object
private
keys of attributes.
-
#_attributes_keys ⇒ Object
private
maps attribute value to explicit key name.
- #attribute(attr, options = {}, &block) ⇒ Object
- #attributes(*attrs) ⇒ Object
- #inherited(base) ⇒ Object
Instance Method Details
#_attributes ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
keys of attributes
64 65 66 |
# File 'lib/active_model/serializer/concerns/attributes.rb', line 64 def _attributes _attributes_data.keys end |
#_attributes_keys ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
maps attribute value to explicit key name
72 73 74 75 76 77 78 |
# File 'lib/active_model/serializer/concerns/attributes.rb', line 72 def _attributes_keys _attributes_data .each_with_object({}) do |(key, attr), hash| next if key == attr.name hash[attr.name] = { key: key } end end |
#attribute(attr, options = {}, &block) ⇒ Object
56 57 58 59 |
# File 'lib/active_model/serializer/concerns/attributes.rb', line 56 def attribute(attr, = {}, &block) key = .fetch(:key, attr) _attributes_data[key] = Attribute.new(attr, , block) end |
#attributes(*attrs) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/active_model/serializer/concerns/attributes.rb', line 36 def attributes(*attrs) attrs = attrs.first if attrs.first.class == Array attrs.each do |attr| attribute(attr) end end |
#inherited(base) ⇒ Object
28 29 30 31 |
# File 'lib/active_model/serializer/concerns/attributes.rb', line 28 def inherited(base) super base._attributes_data = _attributes_data.dup end |