active_admin_import 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTA3MGRlYzRhODQwNmRiM2U2ZWJmYmIzOWJhYWU5OWUzMTQxYTIxOA==
4
+ ZmIxYjFiOTVhMjUxYzVmZGEyZDdkM2I5ZTM4MTdiNTgyOTA1YzZjYQ==
5
5
  data.tar.gz: !binary |-
6
- YzE2ZWQ2YmU0ZmU4NWVmNzZlOTM5OWRmNDU0MTljMzhlNmIyYzAyYQ==
6
+ OWU1MDI1YjMwNjM1MmIxOWU4MTQ5NDlkNGMzODQ1OGM5YWM4OGQ4NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YzRjM2M1OGYzZjMwYzZlZTk1MDgyMTZjMWE3NWI5MzQyNGMyN2FlYTNhMGNh
10
- MzdmZmM3YTdiZDA2MzA1YTExYWZkN2QyZjhkNDI2OTlhYjYzNmMwYTM2YWZj
11
- Mzg2MzFiM2FmY2MzNjBmMzUwMzRhYWU5ZWEyMjg1NzNhOGUwZTg=
9
+ YWE2ZjlmODU1ZTlkMDA1ZmZmODFhYzRhN2VhNjBjM2RlZTEzZTFiZWM4NzY4
10
+ MTBjNDI2OGE1YWM4MTJlYjUwNmM2Y2NlZWIxM2EwNDAwZTUzNzU2YjljZGRj
11
+ MjI4ODU3ZTVlYjA5MzMwMWJjZWEyOGFmOTkyYWM2OGY0NjIyZmY=
12
12
  data.tar.gz: !binary |-
13
- YzJiYzM5NzQwODE3NTFhZTMxOTMwM2JlMGEzYmVmODAxZTA1YjQ5OWYyYzUz
14
- OWQ3NjM1YTdhMzUwM2E1OGJlMDUzM2I5OWEzMTcyOGYwNzU3N2JiMjkzZDJm
15
- ZDM3YzA2ODIyOTExMDk1NGVhZWNmOGE4ZTc5NGZmYmJlMWZlMDY=
13
+ YzA1ZTY1NjVjYzUwOTYwZGQ4MWMzMTdlOTg0Y2FjZmMyZjc3NGUyNGIzNmVl
14
+ YjFkZmM1NDMwMDFlNDJhZDQ1N2YyNjVjMGJmYmQ2NjQ1NjQwOTdjODY4Mjlk
15
+ YWU2ZWZjNzRjMjYxOTg3Mjg2MmMzMTE3ODlkOGI0MWI1NDliNjQ=
@@ -6,6 +6,6 @@
6
6
  <%= f.input :file, as: :file %>
7
7
  <% end %>
8
8
  <%= f.actions do %>
9
- <%= f.action :submit, label: t("active_admin_import.import_btn"), button_html: {disable_with: t("active_admin_import.import_btn_disabled")} %>
9
+ <%= f.action :submit, label: t("active_admin_import.import_btn"), button_html: {data: {disable_with: t("active_admin_import.import_btn_disabled")}} %>
10
10
  <% end %>
11
11
  <% end %>
File without changes
File without changes
@@ -7,11 +7,3 @@ require 'active_admin_import/importer'
7
7
  require 'active_admin_import/model'
8
8
  ::ActiveAdmin::DSL.send(:include, ActiveAdminImport::DSL)
9
9
 
10
- module ActiveAdminImport
11
- class Railtie < ::Rails::Railtie
12
- config.after_initialize do
13
- require 'active_support/i18n'
14
- I18n.load_path.unshift *Dir[File.expand_path('../active_admin_import/locales/*.yml', __FILE__)]
15
- end
16
- end
17
- end
@@ -22,7 +22,7 @@ module ActiveAdminImport
22
22
  # +resource_label+:: resource label value (default config.resource_label)
23
23
  # +plural_resource_label+:: plaralized resource label value (default config.plural_resource_label)
24
24
  #
25
- def active_admin_import options = {}
25
+ def active_admin_import options = {}, &block
26
26
  default_options = {
27
27
  back: {action: :import},
28
28
  csv_options: {},
@@ -51,31 +51,24 @@ module ActiveAdminImport
51
51
  @active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
52
52
  #go back to form
53
53
  return render template: options[:template] unless @active_admin_import_model.valid?
54
-
55
- importer = Importer.new(options[:resource_class],
56
- @active_admin_import_model,
57
- options
58
- )
54
+ @importer = Importer.new(options[:resource_class], @active_admin_import_model, options)
59
55
  begin
60
- result = importer.import
61
- model_name = options[:resource_label].downcase
62
- plural_model_name = options[:resource_label].downcase
63
- flash[:notice] = I18n.t('active_admin_import.imported',
64
- count: result[:imported].to_i,
65
- model: model_name,
66
- plural_model: plural_model_name
67
- ) if result[:imported].to_i > 0
68
-
69
- flash[:error] = I18n.t('active_admin_import.failed',
70
- count: result[:failed].count,
71
- model: model_name,
72
- plural_model: plural_model_name
73
- ) if result[:failed].count > 0
74
- rescue ActiveRecord::Import::MissingColumnError => e
75
- flash[:error] = e.message
56
+ @importer.import
57
+ if block_given?
58
+ instance_eval &block
59
+ else
60
+ model_name = options[:resource_label].downcase
61
+ plural_model_name = options[:resource_label].downcase
62
+ if @importer.result[:imported].to_i > 0
63
+ flash[:notice] = I18n.t('active_admin_import.imported', count: @importer.result[:imported].to_i, model: model_name, plural_model: plural_model_name)
64
+ end
65
+ if @importer.result[:failed].count > 0
66
+ flash[:error] = I18n.t('active_admin_import.failed', count: @importer.result[:failed].count, model: model_name, plural_model: plural_model_name)
67
+ end
68
+ end
69
+ rescue ActiveRecord::Import::MissingColumnError, NoMethodError => e
70
+ flash[:error] = e.message
76
71
  end
77
-
78
-
79
72
  redirect_to options[:back]
80
73
  end
81
74
 
@@ -1,7 +1,7 @@
1
1
  require 'rails'
2
2
 
3
3
  module ActiveAdminImport
4
- class Engine < Rails::Engine
4
+ class Engine < ::Rails::Engine
5
5
 
6
6
  config.mount_at = '/'
7
7
 
@@ -62,6 +62,7 @@ module ActiveAdminImport
62
62
  # capture headers if not exist
63
63
  prepare_headers(headers.any? ? headers : CSV.parse(f.readline, @csv_options).first)
64
64
  f.each_line do |line|
65
+ next if line.blank?
65
66
  lines << line
66
67
  if lines.size == batch_size || f.eof?
67
68
  cycle lines
@@ -8,8 +8,8 @@ module ActiveAdminImport
8
8
  validates :file, presence: {message: Proc.new { I18n.t('active_admin_import.no_file_error') }},
9
9
  unless: proc { |me| me.new_record? }
10
10
 
11
- validate :correct_content_type
12
- validate :file_contents_present
11
+ validate :correct_content_type, if: proc { |me| me.file.present? }
12
+ validate :file_contents_present, if: proc { |me| me.file.present? }
13
13
 
14
14
 
15
15
  before_validation :uncompress_file, if: proc { |me| me.archive? && me.allow_archive? }
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminImport
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Fedoronchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord-import
@@ -78,12 +78,12 @@ files:
78
78
  - Rakefile
79
79
  - active_admin_import.gemspec
80
80
  - app/views/admin/import.html.erb
81
+ - config/locales/en.yml
82
+ - config/locales/it.yml
81
83
  - lib/active_admin_import.rb
82
84
  - lib/active_admin_import/dsl.rb
83
85
  - lib/active_admin_import/engine.rb
84
86
  - lib/active_admin_import/importer.rb
85
- - lib/active_admin_import/locales/en.yml
86
- - lib/active_admin_import/locales/it.yml
87
87
  - lib/active_admin_import/model.rb
88
88
  - lib/active_admin_import/version.rb
89
89
  homepage: http://github.com/Fivell/active_admin_import