Class: CapsuleCRM::Serializer
- Inherits:
-
Object
- Object
- CapsuleCRM::Serializer
- Defined in:
- lib/capsule_crm/serializer.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #collection_root ⇒ Object
-
#initialize(options = {}) ⇒ Serializer
constructor
A new instance of Serializer.
- #root ⇒ Object
- #serialize(object) ⇒ Object
- #serialize_with_root ⇒ Object
- #serialize_without_root ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Serializer
Returns a new instance of Serializer.
5 6 7 |
# File 'lib/capsule_crm/serializer.rb', line 5 def initialize( = {}) @options = end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/capsule_crm/serializer.rb', line 3 def object @object end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/capsule_crm/serializer.rb', line 3 def @options end |
Class Method Details
.serialize_collection(klass, collection) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/capsule_crm/serializer.rb', line 14 def self.serialize_collection(klass, collection) collection = collection.map do |item| = klass..dup .include_root = false ::CapsuleCRM::Serializer.new().serialize(item) end { klass..root => collection } end |
Instance Method Details
#collection_root ⇒ Object
36 37 38 |
# File 'lib/capsule_crm/serializer.rb', line 36 def collection_root @collection_root ||= .collection_root || root.pluralize end |
#root ⇒ Object
31 32 33 34 |
# File 'lib/capsule_crm/serializer.rb', line 31 def root @root ||= .root || object.class.to_s.demodulize.downcase.singularize.camelize(:lower) end |
#serialize(object) ⇒ Object
9 10 11 12 |
# File 'lib/capsule_crm/serializer.rb', line 9 def serialize(object) @object = object include_root? ? serialize_with_root : serialize_without_root end |
#serialize_with_root ⇒ Object
23 24 25 |
# File 'lib/capsule_crm/serializer.rb', line 23 def serialize_with_root { root => build_attributes_hash }.stringify_keys end |
#serialize_without_root ⇒ Object
27 28 29 |
# File 'lib/capsule_crm/serializer.rb', line 27 def serialize_without_root build_attributes_hash end |