diff options
| author | Zog | 2018-02-14 15:13:21 +0100 | 
|---|---|---|
| committer | Johan Van Ryseghem | 2018-02-20 09:50:28 +0100 | 
| commit | 736bd34d8c496b81d456d4e4897197eac344247d (patch) | |
| tree | 59a3b5c324b433286d19320ec873e37dd9fa40db /app/models/simple_importer.rb | |
| parent | 786aca6d55f05af6ecb95dbd845e796d213df044 (diff) | |
| download | chouette-core-736bd34d8c496b81d456d4e4897197eac344247d.tar.bz2 | |
Refs #5924 @2h; Update specs
Diffstat (limited to 'app/models/simple_importer.rb')
| -rw-r--r-- | app/models/simple_importer.rb | 15 | 
1 files changed, 10 insertions, 5 deletions
diff --git a/app/models/simple_importer.rb b/app/models/simple_importer.rb index 41ce379db..bf6f3b406 100644 --- a/app/models/simple_importer.rb +++ b/app/models/simple_importer.rb @@ -55,7 +55,7 @@ class SimpleImporter < ActiveRecord::Base      statuses = ""      log "#{"%#{padding}d" % 0}/#{number_of_lines}", clear: true      ActiveRecord::Base.transaction do -      self.configuration.before_actions(:all).each &:call +      self.configuration.before_actions(:all).each do |action| action.call self end        CSV.foreach(filepath, self.configuration.csv_options) do |row|          status = handle_row row, status @@ -63,7 +63,7 @@ class SimpleImporter < ActiveRecord::Base          fail_with_error ->(){ @current_record.errors.messages } do            new_record = @current_record.new_record?            self.configuration.before_actions(:each_save).each do |action| -            action.call @current_record +            action.call self, @current_record            end            ### This could fail if the record has a mandatory relation which is not yet resolved            ### TODO: do not attempt to save if the current record if waiting for resolution @@ -162,7 +162,7 @@ class SimpleImporter < ActiveRecord::Base    end    class Configuration -    attr_accessor :model, :headers, :separator, :key, :context +    attr_accessor :model, :headers, :separator, :key, :context, :encoding      attr_reader :columns      def initialize import_name, opts={} @@ -170,8 +170,10 @@ class SimpleImporter < ActiveRecord::Base        @key = opts[:key] || "id"        @headers = opts.has_key?(:headers) ? opts[:headers] : true        @separator = opts[:separator] || "," +      @encoding = opts[:encoding]        @columns = opts[:columns] || []        @model = opts[:model] +      @custom_handler = opts[:custom_handler]      end      def duplicate @@ -183,8 +185,10 @@ class SimpleImporter < ActiveRecord::Base          key: @key,          headers: @headers,          separator: @separator, +        encoding: @encoding,          columns: @columns.map(&:duplicate), -        model: model +        model: model, +        custom_handler: @custom_handler        }      end @@ -204,7 +208,8 @@ class SimpleImporter < ActiveRecord::Base      def csv_options        {          headers: self.headers, -        col_sep: self.separator +        col_sep: self.separator, +        encoding: self.encoding        }      end  | 
