Class: ApiResource::Serializer
- Inherits:
-
Object
- Object
- ApiResource::Serializer
- Defined in:
- lib/api_resource/serializer.rb
Overview
Handles serialization for a given instance of ApiResource::Base with a set of options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(record, options = {}) ⇒ Serializer
constructor
Constructor.
-
#to_hash ⇒ HashWithIndifferentAccess
Return our serialized object as a Hash.
Constructor Details
#initialize(record, options = {}) ⇒ Serializer
Constructor
explicitly exclude Associations to explicitly include Attributes to explicitly include the primary key to include attributes that are blank/nil in the serialized hash
36 37 38 39 |
# File 'lib/api_resource/serializer.rb', line 36 def initialize(record, = {}) @record = record @options = .with_indifferent_access end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
13 14 15 |
# File 'lib/api_resource/serializer.rb', line 13 def @options end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
17 18 19 |
# File 'lib/api_resource/serializer.rb', line 17 def record @record end |
Instance Method Details
#to_hash ⇒ HashWithIndifferentAccess
Return our serialized object as a Hash
45 46 47 48 49 50 51 52 |
# File 'lib/api_resource/serializer.rb', line 45 def to_hash ret = HashWithIndifferentAccess.new ret.merge!(self.attributes_for_hash) ret.merge!(self.associations_for_hash) ret.merge!(self.add_on_data_for_hash) ret.merge!(self.association_foreign_keys_for_hash) ret end |