Class: Height::Model::Base
- Inherits:
-
Object
- Object
- Height::Model::Base
- Defined in:
- lib/height/model/base.rb
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Base
constructor
A new instance of Base.
- #related_models ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/height/model/base.rb', line 5 def initialize(attrs) inflector = Dry::Inflector.new self.attributes.each do |name| key = inflector.camelize_lower(name.to_s) self.instance_variable_set("@#{name}", attrs[key]) define_singleton_method(name) do self.instance_variable_get("@#{name}") end end self..each do |name| key = inflector.camelize_lower(name.to_s) next unless attrs[key] items = Height::ListResponse.build(attrs[key]) self.instance_variable_set("@#{name}", items) define_singleton_method(name) do self.instance_variable_get("@#{name}") end end end |
Instance Method Details
#related_models ⇒ Object
30 31 32 |
# File 'lib/height/model/base.rb', line 30 def [] end |