Module: Decoradar::InstanceMethods

Defined in:
lib/decoradar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



61
62
63
# File 'lib/decoradar.rb', line 61

def model
  @model
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



67
68
69
70
71
# File 'lib/decoradar.rb', line 67

def as_json(_options = nil)
  self.class.attribute_set.reduce({}) do |json, attribute|
    enrich_json(json, attribute)
  end
end

#enrich_json(json, attribute) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/decoradar.rb', line 73

def enrich_json(json, attribute)
  if attribute.including?(model)
    attribute.serialize(json, value_of(attribute))
  else
    json
  end
end

#initialize(model) ⇒ Object



63
64
65
# File 'lib/decoradar.rb', line 63

def initialize(model)
  @model = model
end

#value_of(attribute) ⇒ Object



81
82
83
# File 'lib/decoradar.rb', line 81

def value_of(attribute)
  self.public_send(attribute.name.to_sym)
end