Class: FastSerializer::JsonModel::Object
- Defined in:
- lib/fast_serializer/json_model/object.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
Instance Method Summary collapse
- #add_attribute(attribute) ⇒ Object
- #included? ⇒ Boolean
-
#initialize ⇒ Object
constructor
A new instance of Object.
- #serialize(resource, params, context) ⇒ Hash
Methods inherited from Node
Constructor Details
#initialize ⇒ Object
Returns a new instance of Object.
7 8 9 10 |
# File 'lib/fast_serializer/json_model/object.rb', line 7 def initialize super @attributes = {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/fast_serializer/json_model/object.rb', line 5 def attributes @attributes end |
Instance Method Details
#add_attribute(attribute) ⇒ Object
13 14 15 |
# File 'lib/fast_serializer/json_model/object.rb', line 13 def add_attribute(attribute) attributes[attribute.key] = attribute end |
#included? ⇒ Boolean
37 38 39 |
# File 'lib/fast_serializer/json_model/object.rb', line 37 def included?(*) true end |
#serialize(resource, params, context) ⇒ Hash
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fast_serializer/json_model/object.rb', line 21 def serialize(resource, params, context) return if !resource result = {} attributes.each do |_, attribute| next unless attribute.included?(resource, params, context) val = attribute.serialize(resource, params, context) result[attribute.key] = val end result end |