lib/neo4j/shared/property.rb in neo4j-6.0.0.alpha.11 vs lib/neo4j/shared/property.rb in neo4j-6.0.0.alpha.12
- old
+ new
@@ -82,17 +82,19 @@
writer_method_props[key] = attributes.delete(key) if self.respond_to?("#{key}=")
end
end
end
+ DATE_KEY_REGEX = /\A([^\(]+)\((\d+)([if])\)$/
# Gives support for Rails date_select, datetime_select, time_select helpers.
def process_attributes(attributes = nil)
return attributes if attributes.blank?
multi_parameter_attributes = {}
new_attributes = {}
attributes.each_pair do |key, value|
- if match = key.match(/\A([^\(]+)\((\d+)([if])\)$/)
+ if key.match(DATE_KEY_REGEX)
+ match = key.to_s.match(DATE_KEY_REGEX)
found_key = match[1]
index = match[2].to_i
(multi_parameter_attributes[found_key] ||= {})[index] = value.empty? ? nil : value.send("to_#{$3}")
else
new_attributes[key] = value
@@ -103,10 +105,9 @@
end
def process_multiparameter_attributes(multi_parameter_attributes, new_attributes)
multi_parameter_attributes.each_with_object(new_attributes) do |(key, values), attributes|
values = (values.keys.min..values.keys.max).map { |i| values[i] }
-
if (field = self.class.attributes[key.to_sym]).nil?
fail MultiparameterAssignmentError, "error on assignment #{values.inspect} to #{key}"
end
attributes[key] = instantiate_object(field, values)