Class: EasySerializer::AttributeSerializer
- Inherits:
-
Struct
- Object
- Struct
- EasySerializer::AttributeSerializer
show all
- Includes:
- Helpers
- Defined in:
- lib/easy_serializer/attribute_serializer.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#cache_key, #option_to_value
Instance Attribute Details
Returns the value of attribute metadata
2
3
4
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 2
def metadata
@metadata
end
|
#serializer ⇒ Object
Returns the value of attribute serializer
2
3
4
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 2
def serializer
@serializer
end
|
Class Method Details
.call(serializer, metadata) ⇒ Object
4
5
6
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 4
def self.call(serializer, metadata)
new(serializer, metadata).value
end
|
Instance Method Details
#attr_serializer ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 26
def attr_serializer
value = cache_or_attribute
return value.output if value.is_a?(CacheOutput)
return value unless metadata.nested_serializer?
if metadata.is_a? Collection
ary = value.is_a?(Array) ? value : (value == nil ? [] : [value])
ary.map { |o| nested_serialization!(o) }
else
nested_serialization!(value)
end
end
|
#cache_or_attribute ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 39
def cache_or_attribute
if EasySerializer.perform_caching && metadata.catch?
Cacher.new(serializer, metadata).execute
else
serializer.instance_exec object, &metadata.get_value
end
end
|
#nested_serialization!(value) ⇒ Object
47
48
49
50
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 47
def nested_serialization!(value)
return unless value
metadata.serialize!(value, serializer)
end
|
#object ⇒ Object
8
9
10
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 8
def object
serializer.object
end
|
#value ⇒ Object
12
13
14
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 12
def value
value_or_default
end
|
#value_or_default ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/easy_serializer/attribute_serializer.rb', line 16
def value_or_default
value = attr_serializer
if value.nil?
return metadata.get_default(object, serializer)
end
value
end
|