Module: GCPT::JSONable

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



12
13
14
# File 'lib/gcpt/utils/json_model.rb', line 12

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#as_json(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/gcpt/utils/json_model.rb', line 16

def as_json options = {}
  serialized = Hash.new
  self.class.attributes.each do |attribute|
    value = self.public_send(attribute)
    serialized[attribute] = value if !value.nil?
  end
  serialized
end

#to_json(*a) ⇒ Object



25
26
27
# File 'lib/gcpt/utils/json_model.rb', line 25

def to_json *a
  as_json.to_json *a
end