# File lib/tire/model/persistence/attributes.rb, line 84 def initialize(attributes={}) __update_attributes(attributes) end
Casts the values according to the :class
option set when
defining the property, cast Hashes as Hashr instances and automatically
convert UTC formatted strings to Time.
# File lib/tire/model/persistence/attributes.rb, line 110 def __cast_value(name, value) case when klass = self.class.property_types[name.to_sym] if klass.is_a?(Array) && value.is_a?(Array) value.map { |v| klass.first.new(v) } else klass.new(value) end when value.is_a?(Hash) Hashr.new(value) else # Strings formatted as <http://en.wikipedia.org/wiki/ISO8601> are automatically converted to Time value = Time.parse(value) if value.is_a?(String) && value =~ %r^\d{4}[\/\-]\d{2}[\/\-]\d{2}T\d{2}\:\d{2}\:\d{2}Z$/ value end end
# File lib/tire/model/persistence/attributes.rb, line 102 def __update_attributes(attributes) attributes.each { |name, value| send "#{name}=", __cast_value(name, value) } end
# File lib/tire/model/persistence/attributes.rb, line 93 def attribute_names self.class.properties.sort end
# File lib/tire/model/persistence/attributes.rb, line 88 def attributes self.class.properties. inject( self.id ? {'id' => self.id} : {} ) {|attributes, key| attributes[key] = send(key); attributes} end
# File lib/tire/model/persistence/attributes.rb, line 97 def has_attribute?(name) properties.include?(name.to_s) end