Class: Serdee::Attributes::Nested
- Inherits:
-
Object
- Object
- Serdee::Attributes::Nested
- Includes:
- ClassMethods
- Defined in:
- lib/serdee/attributes.rb
Instance Attribute Summary collapse
-
#attributes_class ⇒ Object
readonly
Returns the value of attribute attributes_class.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #extract_to(data, obj) ⇒ Object
-
#initialize(attributes_class, key, serializers, &block) ⇒ Nested
constructor
A new instance of Nested.
- #insert_to(obj, data) ⇒ Object
Methods included from ClassMethods
#attribute, #attributes, #deserialize_key, #from_json, #key_transform, #nested, #of_json, #serialize_key, #serializers
Constructor Details
#initialize(attributes_class, key, serializers, &block) ⇒ Nested
Returns a new instance of Nested.
143 144 145 146 147 148 |
# File 'lib/serdee/attributes.rb', line 143 def initialize(attributes_class, key, serializers, &block) @attributes_class = attributes_class @key = key @serializers = serializers instance_eval(&block) if block_given? end |
Instance Attribute Details
#attributes_class ⇒ Object (readonly)
Returns the value of attribute attributes_class.
142 143 144 |
# File 'lib/serdee/attributes.rb', line 142 def attributes_class @attributes_class end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
142 143 144 |
# File 'lib/serdee/attributes.rb', line 142 def key @key end |
Instance Method Details
#extract_to(data, obj) ⇒ Object
150 151 152 153 |
# File 'lib/serdee/attributes.rb', line 150 def extract_to(data, obj) return if data.nil? || data[key].nil? super(data[key], obj) end |
#insert_to(obj, data) ⇒ Object
155 156 157 158 |
# File 'lib/serdee/attributes.rb', line 155 def insert_to(obj, data) data[key] = {} super(obj, data[key]) end |