Module: Modis::Attributes

Defined in:
lib/modis/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

TYPES =
[:string, :integer, :float, :timestamp, :boolean, :array, :hash]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/modis/attributes.rb', line 5

def self.included(base)
  base.extend ClassMethods

  base.instance_eval do
    bootstrap_attributes
  end
end

Instance Method Details

#assign_attributes(hash) ⇒ Object



49
50
51
52
53
54
# File 'lib/modis/attributes.rb', line 49

def assign_attributes(hash)
  hash.each do |k, v|
    setter = "#{k}="
    send(setter, v) if respond_to?(setter)
  end
end

#attributesObject



45
46
47
# File 'lib/modis/attributes.rb', line 45

def attributes
  @attributes ||= Hash[self.class.attributes.keys.zip]
end

#write_attribute(key, value) ⇒ Object



56
57
58
# File 'lib/modis/attributes.rb', line 56

def write_attribute(key, value)
  attributes[key.to_s] = value
end