Class: Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bob/models/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
12
13
# File 'lib/bob/models/base.rb', line 5

def initialize(raw)
  attributes = Bob::Util.underscorize_hash(raw)

  attributes.each do |k, v|
    instance_variable_set("@#{k}", v.is_a?(Hash) ? Models::Base.new(v) : v)
    self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") })
    self.class.send(:define_method, "#{k}=", proc { |val| instance_variable_set("@#{k}", val) })
  end
end