Module: Gecko::Helpers::SerializationHelper
- Included in:
- Record::Base
- Defined in:
- lib/gecko/helpers/serialization_helper.rb
Overview
Provides serialization to records
Instance Method Summary collapse
-
#as_json ⇒ Hash
private
Returns a full JSON representation of a record.
-
#root ⇒ String
private
Return JSON root key for a record.
-
#serializable_hash ⇒ Hash
private
Return a serialized hash of the record’s attributes.
-
#serialize_attribute(attribute_hash, attribute) ⇒ undefined
private
Serialize a single attribute.
Instance Method Details
#as_json ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a full JSON representation of a record
13 14 15 16 17 |
# File 'lib/gecko/helpers/serialization_helper.rb', line 13 def as_json { root => serializable_hash } end |
#root ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return JSON root key for a record
56 57 58 |
# File 'lib/gecko/helpers/serialization_helper.rb', line 56 def root self.class.demodulized_name.underscore.to_sym end |
#serializable_hash ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a serialized hash of the record’s attributes
27 28 29 30 31 32 33 34 |
# File 'lib/gecko/helpers/serialization_helper.rb', line 27 def serializable_hash attribute_hash = {} attribute_set.each do |attribute| next if attribute.[:readonly] serialize_attribute(attribute_hash, attribute) end attribute_hash end |
#serialize_attribute(attribute_hash, attribute) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Serialize a single attribute
44 45 46 |
# File 'lib/gecko/helpers/serialization_helper.rb', line 44 def serialize_attribute(attribute_hash, attribute) attribute_hash[attribute.name] = attributes[attribute.name] end |