Module: ObjectAttorney::Serialization

Defined in:
lib/object_attorney/serialization.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



20
21
22
23
# File 'lib/object_attorney/serialization.rb', line 20

def self.included(base)
  base.class_eval { include ActiveModel::Serialization }
  base.extend(ClassMethods)
end

Instance Method Details

#attributesObject



5
6
7
8
9
10
# File 'lib/object_attorney/serialization.rb', line 5

def attributes
  self.class.attributes_keys.reduce({}) do |data, getter|
    data[getter.to_s] = send(getter)
    data
  end
end

#to_hash(options = {}) ⇒ Object



12
13
14
# File 'lib/object_attorney/serialization.rb', line 12

def to_hash(options = {})
  serializable_hash(options)
end

#to_json(options = {}) ⇒ Object



16
17
18
# File 'lib/object_attorney/serialization.rb', line 16

def to_json(options = {})
  serializable_hash(options).to_json
end