lib/neo4j/active_node/property.rb in neo4j-3.0.0.alpha.7 vs lib/neo4j/active_node/property.rb in neo4j-3.0.0.alpha.8
- old
+ new
@@ -13,13 +13,11 @@
end
def initialize(attributes={}, options={})
relationship_props = self.class.extract_relationship_attributes!(attributes)
writer_method_props = extract_writer_methods!(attributes)
-
validate_attributes!(attributes)
-
writer_method_props.each do |key, value|
self.send("#{key}=", value)
end
super(attributes, options)
@@ -57,15 +55,19 @@
end
module ClassMethods
def property(name, options={})
- # Magic properties
- options[:type] = DateTime if name.to_sym == :created_at || name.to_sym == :updated_at
+ magic_properties(name, options)
+
+ # if (name.to_s == 'remember_created_at')
+ # binding.pry
+ # end
attribute(name, options)
end
+ #overrides ActiveAttr's attribute! method
def attribute!(name, options={})
super(name, options)
define_method("#{name}=") do |value|
typecast_value = typecast_attribute(typecaster_for(self.class._attribute_type(name)), value)
send("#{name}_will_change!") unless typecast_value == read_attribute(name)
@@ -79,9 +81,27 @@
attributes.keys.inject({}) do |relationship_props, key|
relationship_props[key] = attributes.delete(key) if self.has_relationship?(key)
relationship_props
end
+ end
+
+ private
+
+ # Tweaks properties
+ def magic_properties(name, options)
+ set_stamp_type(name, options)
+ set_time_as_datetime(options)
+ end
+
+ def set_stamp_type(name, options)
+ options[:type] = DateTime if (name.to_sym == :created_at || name.to_sym == :updated_at)
+ end
+
+ # ActiveAttr does not handle "Time", Rails and Neo4j.rb 2.3 did
+ # Convert it to DateTime in the interest of consistency
+ def set_time_as_datetime(options)
+ options[:type] = DateTime if options[:type] == Time
end
end
end