lib/neo4j/shared/property.rb in neo4j-3.0.0.rc.3 vs lib/neo4j/shared/property.rb in neo4j-3.0.0.rc.4
- old
+ new
@@ -37,20 +37,19 @@
end
alias_method :[], :read_attribute
def default_properties=(properties)
keys = self.class.default_properties.keys
- @default_properties = properties.reject{|key| !keys.include?(key)}
+ @default_properties = properties.select {|key| keys.include?(key) }
end
def default_property(key)
- keys = self.class.default_properties.keys
- keys.include?(key.to_sym) ? default_properties[key.to_sym] : nil
+ default_properties[key.to_sym]
end
def default_properties
- @default_properties ||= {}
+ @default_properties ||= Hash.new(nil)
# keys = self.class.default_properties.keys
# _persisted_obj.props.reject{|key| !keys.include?(key)}
end
def send_props(hash)
@@ -151,21 +150,31 @@
magic_properties(name, options)
attribute(name, options)
constraint_or_index(name, options)
end
+ def undef_property(name)
+ raise ArgumentError, "Argument `#{name}` not an attribute" if not attribute_names.include?(name.to_s)
+
+ attribute_methods(name).each do |method|
+ undef_method(method)
+ end
+
+ undef_constraint_or_index(name)
+ end
+
def default_property(name, &block)
default_properties[name] = block
end
# @return [Hash<Symbol,Proc>]
def default_properties
@default_property ||= {}
end
def default_property_values(instance)
- default_properties.inject({}) do |result,pair|
- result.tap{|obj| obj[pair[0]] = pair[1].call(instance)}
+ default_properties.each_with_object({}) do |(key, block),result|
+ result[key] = block.call(instance)
end
end
def attribute!(name, options={})
super(name, options)