Class: Height::Model::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/height/model/base.rb

Direct Known Subclasses

Activity, List, Task, User

Instance Method Summary collapse

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.related_models.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



30
31
32
# File 'lib/height/model/base.rb', line 30

def related_models
  []
end