diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/activeattr_ext.rb | 39 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 7 |
2 files changed, 43 insertions, 3 deletions
diff --git a/lib/activeattr_ext.rb b/lib/activeattr_ext.rb new file mode 100644 index 000000000..b4c112b72 --- /dev/null +++ b/lib/activeattr_ext.rb @@ -0,0 +1,39 @@ +module ActiveAttr::MultiParameterAttributes + + def assign_attributes(new_attributes, options = {}) + super( + expand_multiparameter_attributes(new_attributes), + options + ) + end + + def expand_multiparameter_attributes(attributes) + attributes ||= {} + + single_parameter_attributes = {} + multi_parameter_attributes = {} + + attributes.each do |key, value| + matches = key.match(/^(?<key>[^\(]+)\((?<index>\d+)i\)$/) + + unless matches + single_parameter_attributes[key] = value + next + end + + args = (multi_parameter_attributes[matches['key']] ||= []) + args[matches['index'].to_i - 1] = (value.present? ? value.to_i : nil) + end + + single_parameter_attributes.merge( + multi_parameter_attributes.inject({}) do |hash, (key, args)| + if args.all?(&:present?) + hash.merge(key => _attribute_type(key).new(*args)) + else + hash + end + end + ) + end + +end diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 9c5ff7cd4..68f7fc621 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -147,7 +147,8 @@ module Stif :area_type => 'TypeOfPlaceRef', :object_version => 'version', :zip_code => 'PostalRegion', - :city_name => 'Town' + :city_name => 'Town', + :stif_type => 'OBJECT_STATUS' }.each do |k, v| stop[k] = entry[v] end if entry['gml:pos'] @@ -156,8 +157,8 @@ module Stif end if stop.changed? - stop.creation_time = entry[:created] - stop.import_xml = entry[:xml] + stop.created_at = entry[:created] + stop.import_xml = entry[:xml] prop = stop.new_record? ? :imported_count : :updated_count increment_counts prop, 1 stop.save! |
