Class: EasySerializer::AttributeSerializer
- Inherits:
-
Struct
- Object
- Struct
- EasySerializer::AttributeSerializer
- Includes:
- Helpers
- Defined in:
- lib/easy_serializer/attribute_serializer.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#serializer ⇒ Object
Returns the value of attribute serializer.
Class Method Summary collapse
Instance Method Summary collapse
- #attr_serializer ⇒ Object
- #cache_or_attribute ⇒ Object
- #nested_serialization!(value) ⇒ Object
- #object ⇒ Object
- #value ⇒ Object
- #value_or_default ⇒ Object
Methods included from Helpers
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata
2 3 4 |
# File 'lib/easy_serializer/attribute_serializer.rb', line 2 def @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, ) new(serializer, ).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 .nested_serializer? if .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 && .catch? Cacher.new(serializer, ).execute else serializer.instance_exec object, &.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 .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 # Check if value is nil # eval option default ( in case is block) if value.nil? return .get_default(object, serializer) end value end |