Module: ActiveModel::Serializer::Attributes::ClassMethods
- Defined in:
- lib/active_model/serializer/attributes.rb
Instance Method Summary (collapse)
-
- (Object) _attributes
private
keys of attributes.
-
- (Object) _attributes_keys
private
maps attribute value to explict key name.
- - (Object) attribute(attr, options = {}, &block)
- - (Object) attributes(*attrs)
- - (Object) inherited(base)
Instance Method Details
- (Object) _attributes
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/attributes.rb', line 64 def _attributes _attributes_data.keys end |
- (Object) _attributes_keys
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 explict key name
72 73 74 75 76 77 78 |
# File 'lib/active_model/serializer/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 |
- (Object) attribute(attr, options = {}, &block)
56 57 58 59 |
# File 'lib/active_model/serializer/attributes.rb', line 56 def attribute(attr, = {}, &block) key = .fetch(:key, attr) _attributes_data[key] = Attribute.new(attr, , block) end |
- (Object) attributes(*attrs)
36 37 38 39 40 41 42 |
# File 'lib/active_model/serializer/attributes.rb', line 36 def attributes(*attrs) attrs = attrs.first if attrs.first.class == Array attrs.each do |attr| attribute(attr) end end |
- (Object) inherited(base)
28 29 30 31 |
# File 'lib/active_model/serializer/attributes.rb', line 28 def inherited(base) super base._attributes_data = _attributes_data.dup end |