Class: Serdee::Attributes::Nested

Inherits:
Object
  • Object
show all
Includes:
ClassMethods
Defined in:
lib/serdee/attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_classObject (readonly)

Returns the value of attribute attributes_class.



142
143
144
# File 'lib/serdee/attributes.rb', line 142

def attributes_class
  @attributes_class
end

#keyObject (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