Module: Rumbly::Model::Simple

Defined in:
lib/rumbly/model/simple.rb

Class Method Summary collapse

Class Method Details

.define_class(classname) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rumbly/model/simple.rb', line 8

def self.define_class(classname)
  parent = Rumbly::Model.const_get(classname)
  cls = Class.new(parent) do
    parent::ATTRIBUTES.keys.each { |a| attr_accessor a }
    def initialize (attrs={})
      (self.class.superclass)::ATTRIBUTES.each_pair do |a,v|
        instance_variable_set("@#{a}", attrs[a] || v)
      end
    end
  end
  const_set(classname, cls)
end