Module: Decoradar::InstanceMethods
- Defined in:
- lib/decoradar.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #as_json(_options = nil) ⇒ Object
- #enrich_json(json, attribute) ⇒ Object
- #initialize(model) ⇒ Object
- #value_of(attribute) ⇒ Object
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
68 69 70 |
# File 'lib/decoradar.rb', line 68 def model @model end |
Instance Method Details
#as_json(_options = nil) ⇒ Object
74 75 76 77 78 |
# File 'lib/decoradar.rb', line 74 def as_json( = nil) self.class.attribute_set.reduce({}) do |json, attribute| enrich_json(json, attribute) end end |
#enrich_json(json, attribute) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/decoradar.rb', line 80 def enrich_json(json, attribute) if attribute.including?(model) attribute.serialize(json, value_of(attribute)) else json end end |
#initialize(model) ⇒ Object
70 71 72 |
# File 'lib/decoradar.rb', line 70 def initialize(model) @model = model end |
#value_of(attribute) ⇒ Object
88 89 90 |
# File 'lib/decoradar.rb', line 88 def value_of(attribute) self.public_send(attribute.name.to_sym) end |