Module: Modis::Attribute
- Defined in:
- lib/modis/attribute.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
- #assign_attributes(hash) ⇒ Object
- #attributes ⇒ Object
- #read_attribute(key) ⇒ Object
- #write_attribute(key, value) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/modis/attribute.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
48 49 50 51 52 53 |
# File 'lib/modis/attribute.rb', line 48 def assign_attributes(hash) hash.each do |k, v| setter = "#{k}=" send(setter, v) if respond_to?(setter) end end |
#attributes ⇒ Object
44 45 46 |
# File 'lib/modis/attribute.rb', line 44 def attributes @attributes ||= Hash[self.class.attributes.keys.zip] end |
#read_attribute(key) ⇒ Object
59 60 61 |
# File 'lib/modis/attribute.rb', line 59 def read_attribute(key) attributes[key.to_s] end |
#write_attribute(key, value) ⇒ Object
55 56 57 |
# File 'lib/modis/attribute.rb', line 55 def write_attribute(key, value) attributes[key.to_s] = value end |