csv_step_importer 0.7.4 → 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38a5dd24101512b6117a0d8d33020b52ccedbeb816b9b49a64473471b471bd64
4
- data.tar.gz: 1c2bccce9e7945daba6bd90ac18aa68a77f14b401f8c1af6bc0f8d619d94dca9
3
+ metadata.gz: 96a84016e041d144dc81796ae295e23d934305f722bd03cb88dc574cbbd460ca
4
+ data.tar.gz: 24d5229cdbe01cacf8ced8fc137a21334a10051ec0917801e83330401db778df
5
5
  SHA512:
6
- metadata.gz: fe1abd4a1c0078c4af1e629e769612c8dce19a718522607e692b3d323ff681cbc83335073e4924d94f2aa6fcdccbe045e638febea102d15625adb742aa65f307
7
- data.tar.gz: a63422a10246541cfa0537538c625c51c55746bfa1730ad718bd2895f6955e87ef8893de3d90cf687d8eb0d9cc25794bb44cf919d21aa1585add255b97f053f5
6
+ metadata.gz: 05ade3ead9a672dd14d214991e1e18f58ed739c479a4a2fe71f7de2c8ce22d41cf5bca5400733be2c637371f1fbf80ec01e013d2544e4534bd9377a49d07056e
7
+ data.tar.gz: d3a9b37b47bac1a099c0942de35f95df534fba5c87fc7fae082365733180f9f056c6982dd38f481d55814b993e795788460300b05be9ccaa9e1323e327d45f26
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csv_step_importer (0.7.4)
4
+ csv_step_importer (0.7.5)
5
5
  activemodel
6
6
  activerecord-import
7
7
  activesupport
@@ -29,7 +29,7 @@ GEM
29
29
  activemodel (= 5.2.0)
30
30
  activesupport (= 5.2.0)
31
31
  arel (>= 9.0)
32
- activerecord-import (0.23.0)
32
+ activerecord-import (0.24.0)
33
33
  activerecord (>= 3.2)
34
34
  activesupport (5.2.0)
35
35
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -45,18 +45,19 @@ GEM
45
45
  erubi (1.7.1)
46
46
  i18n (1.0.1)
47
47
  concurrent-ruby (~> 1.0)
48
+ jaro_winkler (1.5.1)
48
49
  loofah (2.2.2)
49
50
  crass (~> 1.0.2)
50
51
  nokogiri (>= 1.5.9)
51
52
  method_source (0.9.0)
52
53
  mini_portile2 (2.3.0)
53
54
  minitest (5.11.3)
54
- nokogiri (1.8.2)
55
+ nokogiri (1.8.3)
55
56
  mini_portile2 (~> 2.3.0)
56
57
  parallel (1.12.1)
57
58
  parser (2.5.1.0)
58
59
  ast (~> 2.4.0)
59
- powerpack (0.1.1)
60
+ powerpack (0.1.2)
60
61
  rack (2.0.5)
61
62
  rack-test (1.0.0)
62
63
  rack (>= 1.0, < 3)
@@ -86,7 +87,8 @@ GEM
86
87
  diff-lcs (>= 1.2.0, < 2.0)
87
88
  rspec-support (~> 3.7.0)
88
89
  rspec-support (3.7.1)
89
- rubocop (0.56.0)
90
+ rubocop (0.57.2)
91
+ jaro_winkler (~> 1.5.1)
90
92
  parallel (~> 1.10)
91
93
  parser (>= 2.5)
92
94
  powerpack (~> 0.1)
@@ -96,15 +98,15 @@ GEM
96
98
  rubocop-rails (1.4.1)
97
99
  railties (>= 3.0)
98
100
  rubocop (~> 0.53)
99
- rubocop-rspec (1.25.1)
100
- rubocop (>= 0.53.0)
101
+ rubocop-rspec (1.27.0)
102
+ rubocop (>= 0.56.0)
101
103
  ruby-progressbar (1.9.0)
102
104
  smarter_csv (1.2.3)
103
105
  thor (0.20.0)
104
106
  thread_safe (0.3.6)
105
107
  tzinfo (1.2.5)
106
108
  thread_safe (~> 0.1)
107
- unicode-display_width (1.3.3)
109
+ unicode-display_width (1.4.0)
108
110
 
109
111
  PLATFORMS
110
112
  ruby
@@ -118,4 +120,4 @@ DEPENDENCIES
118
120
  rubocop-rspec
119
121
 
120
122
  BUNDLED WITH
121
- 1.16.1
123
+ 1.16.2
data/README.md CHANGED
@@ -15,6 +15,8 @@ Add this line to your application's Gemfile:
15
15
  gem 'csv_step_importer'
16
16
  ```
17
17
 
18
+ NOTE: you might need to add `gem 'smarter_csv', github: 'tilo/smarter_csv'` if you encounter problems building rows
19
+
18
20
  And then execute:
19
21
 
20
22
  $ bundle
@@ -35,8 +35,11 @@ module CSVStepImporter
35
35
 
36
36
  first_row = 2
37
37
 
38
- ::SmarterCSV.process(path, **csv_options.deep_dup) do |rows|
39
- self.headers ||= rows.first&.keys
38
+ options = csv_options.deep_dup
39
+ options[:header_transformations] ||= []
40
+ options[:header_transformations] << header_proc
41
+
42
+ ::SmarterCSV.process(path, **options) do |rows|
40
43
  add_children chunk_class.new(
41
44
  first_row: first_row,
42
45
  parent: self,
@@ -67,5 +70,13 @@ module CSVStepImporter
67
70
  return unless csv_load_error
68
71
  errors[:csv_file] << I18n.t("csv_step_importer.errors.#{csv_load_error.class.name.underscore.gsub(/\//, '_')}")
69
72
  end
73
+
74
+ private
75
+ def header_proc
76
+ Proc.new { |headers|
77
+ self.headers = headers
78
+ headers
79
+ }
80
+ end
70
81
  end
71
82
  end
@@ -26,7 +26,7 @@ module CSVStepImporter
26
26
  end
27
27
  end
28
28
 
29
- def value_for_key key
29
+ def value_for_key(key)
30
30
  if respond_to?(key)
31
31
  send key
32
32
  elsif attributes.include? key
@@ -17,27 +17,31 @@ module CSVStepImporter
17
17
  CSVStepImporter::Model::Importer
18
18
  end
19
19
 
20
- # set to nil in order to deactivate
20
+ # return CSVStepImporter::Model::Reflector in order to enable reflections (e.g. get ids of all rows)
21
+ # disabled by default
21
22
  def reflector_class
22
- # in order to enable reflections return reflector class: CSVStepImporter::Model::Reflector
23
23
  nil
24
24
  end
25
25
 
26
+ # NOTE: required only when reflector class is set
26
27
  # example: env[:company].company_users
27
28
  def finder_scope
28
29
  model_class.all
29
30
  end
30
31
 
32
+ # NOTE: required only when reflector class is set
31
33
  # example: [:email]
32
34
  def finder_keys
33
35
  raise "please extend and implement"
34
36
  end
35
37
 
38
+ # NOTE: required only when importer class is set
36
39
  # see: https://github.com/zdennis/activerecord-import/wiki/On-Duplicate-Key-Update
37
40
  def on_duplicate_key_ignore
38
41
  false
39
42
  end
40
43
 
44
+ # NOTE: required only when importer class is set
41
45
  # example [:email, :updated_at]
42
46
  # see: https://github.com/zdennis/activerecord-import/wiki/On-Duplicate-Key-Update
43
47
  def on_duplicate_key_update
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CSVStepImporter
4
- VERSION = "0.7.4"
4
+ VERSION = "0.7.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_step_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian-Manuel Butzke
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler