module Hashme::Properties
Public Instance Methods
attributes=(attrs = {})
click to toggle source
# File lib/hashme/properties.rb, line 26 def attributes=(attrs = {}) set_attributes(attrs) end
get_attribute(name)
click to toggle source
# File lib/hashme/properties.rb, line 10 def get_attribute(name) self[name] end
set_attribute(name, value)
click to toggle source
# File lib/hashme/properties.rb, line 14 def set_attribute(name, value) property = get_property(name) if property value = property.build(self, value) if value.nil? delete(property.name) else self[property.name] = value end end end
Protected Instance Methods
set_attributes(attrs = {})
click to toggle source
Internal method to go through each attribute and set the values via the set_attribute
method.
# File lib/hashme/properties.rb, line 43 def set_attributes(attrs = {}) attrs.each do |key, value| set_attribute(key, value) end end
set_defaults()
click to toggle source
Go through each property and make sure it has a default value.
# File lib/hashme/properties.rb, line 33 def set_defaults (self.class.properties || {}).each do |key, property| unless property.default.nil? self[property.name] = property.default end end end
Private Instance Methods
get_property(name)
click to toggle source
# File lib/hashme/properties.rb, line 51 def get_property(name) self.class.properties[name.to_sym] end