module Decoradar::InstanceMethods
Attributes
model[R]
Public Class Methods
new(model)
click to toggle source
# File lib/decoradar.rb, line 71 def initialize(model) @model = model end
Public Instance Methods
as_json(_options = nil)
click to toggle source
# File lib/decoradar.rb, line 75 def as_json(_options = nil) self.class.attribute_set.reduce({}) do |json, attribute| enrich_json(json, attribute) end end
Private Instance Methods
enrich_json(json, attribute)
click to toggle source
# File lib/decoradar.rb, line 83 def enrich_json(json, attribute) if attribute.including?(model) attribute.serialize(json, value_of(attribute)) else json end end
value_of(attribute)
click to toggle source
# File lib/decoradar.rb, line 91 def value_of(attribute) attribute_name = attribute.name.to_sym self.public_send(attribute_name) rescue NoMethodError raise Decoradar::AttributeNotFound.new(self, attribute_name) end