From 35786fef17520b754ac97545205326e70015a87a Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Wed, 17 Nov 2010 00:03:52 -0800 Subject: [PATCH] Codify import results in a Struct rather than OpenStruct, as it's a faster, more rigid structure --- lib/activerecord-import/import.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/activerecord-import/import.rb b/lib/activerecord-import/import.rb index 35bb026..5ee440b 100644 --- a/lib/activerecord-import/import.rb +++ b/lib/activerecord-import/import.rb @@ -3,6 +3,9 @@ require "ostruct" module ActiveRecord::Import::ConnectionAdapters ; end module ActiveRecord::Import #:nodoc: + class Result < Struct.new(:failed_instances, :num_inserts) + end + module ImportSupport #:nodoc: def supports_import? #:nodoc: true @@ -200,7 +203,7 @@ class ActiveRecord::Base import_with_validations( column_names, array_of_attributes, options ) else num_inserts = import_without_validations_or_callbacks( column_names, array_of_attributes, options ) - OpenStruct.new :failed_instances=>[], :num_inserts=>num_inserts + ActiveRecord::Import::Result.new([], num_inserts) end if options[:synchronize] @@ -240,7 +243,7 @@ class ActiveRecord::Base array_of_attributes.compact! num_inserts = array_of_attributes.empty? ? 0 : import_without_validations_or_callbacks( column_names, array_of_attributes, options ) - OpenStruct.new :failed_instances=>failed_instances, :num_inserts => num_inserts + ActiveRecord::Import::Result.new(failed_instances, num_inserts) end # Imports the passed in +column_names+ and +array_of_attributes+