Class: EasySerializer::Field
- Inherits:
-
Struct
- Object
- Struct
- EasySerializer::Field
- Includes:
- Helpers
- Defined in:
- lib/easy_serializer/field.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #cache_key ⇒ Object
- #cache_options ⇒ Object
- #catch? ⇒ Boolean
- #get_value ⇒ Object
- #nested_serializer ⇒ Object
- #send_method(obj) ⇒ Object
-
#serialize!(object, serializer_instance) ⇒ Object
Important!!! DO NOT memoize this method.
- #serializer(object, serializer_instance) ⇒ Object (also: #nested_serializer=)
- #serializer? ⇒ Boolean (also: #nested_serializer?)
Methods included from Helpers
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
2 3 4 |
# File 'lib/easy_serializer/field.rb', line 2 def block @block end |
#name ⇒ Object
Returns the value of attribute name
2 3 4 |
# File 'lib/easy_serializer/field.rb', line 2 def name @name end |
#options ⇒ Object
Returns the value of attribute options
2 3 4 |
# File 'lib/easy_serializer/field.rb', line 2 def @options end |
Instance Method Details
#cache_key ⇒ Object
30 31 32 |
# File 'lib/easy_serializer/field.rb', line 30 def cache_key [:cache_key] end |
#cache_options ⇒ Object
26 27 28 |
# File 'lib/easy_serializer/field.rb', line 26 def [:cache_options] end |
#catch? ⇒ Boolean
17 18 19 |
# File 'lib/easy_serializer/field.rb', line 17 def catch? [:cache] end |
#get_value ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/easy_serializer/field.rb', line 5 def get_value if block block else method(:send_method) end end |
#nested_serializer ⇒ Object
34 35 36 |
# File 'lib/easy_serializer/field.rb', line 34 def nested_serializer @serializer end |
#send_method(obj) ⇒ Object
13 14 15 |
# File 'lib/easy_serializer/field.rb', line 13 def send_method(obj) obj.send(name) end |
#serialize!(object, serializer_instance) ⇒ Object
Important!!! DO NOT memoize this method
45 46 47 48 49 |
# File 'lib/easy_serializer/field.rb', line 45 def serialize!(object, serializer_instance) serializer = serializer(object, serializer_instance) return unless serializer serializer.call(object) end |
#serializer(object, serializer_instance) ⇒ Object Also known as: nested_serializer=
38 39 40 41 |
# File 'lib/easy_serializer/field.rb', line 38 def serializer(object, serializer_instance) return unless serializer? option_to_value([:serializer], object, serializer_instance) end |
#serializer? ⇒ Boolean Also known as: nested_serializer?
21 22 23 |
# File 'lib/easy_serializer/field.rb', line 21 def serializer? !![:serializer] end |