active_importer 0.2.5 → 0.2.6

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
  SHA1:
3
- metadata.gz: a6daa340c010143c7efa4f1f94cb5cb1778c13bf
4
- data.tar.gz: a45ede6787d0fee8563973292bd2456133b61ae8
3
+ metadata.gz: bbe08145a2cb895fe8b9c4bf50be71e493cb7a47
4
+ data.tar.gz: 1d2dc2cb3a6c77f0166b798dbc88c1c44083fbeb
5
5
  SHA512:
6
- metadata.gz: 974291103c95864dc5409fa19544fd135ff1485b559193f779a7243e6abd42185ff80d602a6d868b9cc625b7d265a6e06e2e2cf5984e395645e7e4b845631931
7
- data.tar.gz: 608cf19443e5e470d600cb41f0e966cacc53c563a5b68ebaa3e6d93ad4116982e9fb5273fba199ae414fbf43211c7b25894459ce83b55b040da0b689e7d0b0a5
6
+ metadata.gz: 3be7f4e8af60bbb860b5e2954bfcda2ca440d919398bb7acbf9640a3a93580ff7fcd63e1132d591bc3b4c5674d9b2708b2a5e63d1a215e5bd041721c17d60802
7
+ data.tar.gz: a7db2afe6f9bc1b76a90fece19733318d61f231151b3a0ad121eb8b806f0ad6b7774f1398d48e07a37d3775dc3ccc446d7961b6e39f81cb28ee1feb74d7b239a
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["gnapse@gmail.com"]
11
11
  spec.description = %q{Import tabular data from spreadsheets or similar sources into data models}
12
12
  spec.summary = %q{Import tabular data into data models}
13
- spec.homepage = ""
13
+ spec.homepage = "http://continuum.github.io/active_importer/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rspec", "~> 2.14"
26
26
 
27
27
  spec.add_development_dependency "sqlite3"
28
28
  spec.add_development_dependency "activerecord"
@@ -243,9 +243,21 @@ module ActiveImporter
243
243
  self.class.columns
244
244
  end
245
245
 
246
+ def self.skip_row_blocks
247
+ @skip_row_blocks ||= begin
248
+ klass = self
249
+ result = []
250
+ while klass < ActiveImporter::Base
251
+ block = klass.skip_rows_block
252
+ result << block if block
253
+ klass = klass.superclass
254
+ end
255
+ result
256
+ end
257
+ end
258
+
246
259
  def skip_row?
247
- block = self.class.skip_rows_block
248
- block && self.instance_exec(&block)
260
+ self.class.skip_row_blocks.any? { |block| self.instance_exec(&block) }
249
261
  end
250
262
 
251
263
  def load_sheet
@@ -268,7 +280,7 @@ module ActiveImporter
268
280
  def load_header
269
281
  @header_index = find_header_index
270
282
  if @header_index
271
- @header = @book.row(@header_index).map(&:strip)
283
+ @header = @book.row(@header_index).map(&:to_s).map(&:strip)
272
284
  else
273
285
  raise 'Spreadsheet does not contain all the expected columns'
274
286
  end
@@ -278,7 +290,7 @@ module ActiveImporter
278
290
  begin
279
291
  @model = fetch_model
280
292
  build_model
281
- model.save! unless aborted?
293
+ save_model unless aborted?
282
294
  rescue => e
283
295
  @row_errors << { row_index: row_index, error_message: e.message }
284
296
  fire_event :row_error, e
@@ -291,6 +303,10 @@ module ActiveImporter
291
303
  fire_event :row_processed
292
304
  end
293
305
 
306
+ def save_model
307
+ model.save! if model.new_record? || model.changed?
308
+ end
309
+
294
310
  def build_model
295
311
  row.each_pair do |key, value|
296
312
  column_def = columns[key]
@@ -1,3 +1,3 @@
1
1
  module ActiveImporter
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -246,17 +246,18 @@ describe ActiveImporter::Base do
246
246
  [' Name ', 'Birth Date', 'Department', 'Manager'],
247
247
  ['Skip', '2013-10-25', 'IT'],
248
248
  ['John Doe', '2013-10-25', 'IT'],
249
+ ['BaseSkip', '2013-10-25', 'IT'],
249
250
  ['Jane Doe', '2013-10-26', 'Sales'],
250
251
  ]
251
252
  end
252
253
 
253
- it 'skips processing the current row' do
254
+ it 'allows the user to define conditions under which rows should be skipped' do
254
255
  expect { EmployeeImporter.import('/dummy/file') }.to change(Employee, :count).by(2)
255
256
  end
256
257
 
257
258
  it 'invokes event :row_skipped for each skipped row' do
258
259
  expect(EmployeeImporter).to receive(:new).once.and_return(importer)
259
- expect(importer).to receive(:row_skipped).once
260
+ expect(importer).to receive(:row_skipped).twice
260
261
  EmployeeImporter.import('/dummy/file')
261
262
  end
262
263
  end
@@ -1,6 +1,10 @@
1
1
  class EmployeeBaseImporter < ActiveImporter::Base
2
2
  on(:import_finished) { base_import_finished }
3
3
 
4
+ skip_rows_if do
5
+ row['Name'] == 'BaseSkip'
6
+ end
7
+
4
8
  private
5
9
 
6
10
  def base_import_finished
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernesto Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roo
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ files:
117
117
  - spec/support/active_record/schema.rb
118
118
  - spec/support/employee_importer.rb
119
119
  - spec/support/spreadsheet.rb
120
- homepage: ''
120
+ homepage: http://continuum.github.io/active_importer/
121
121
  licenses:
122
122
  - MIT
123
123
  metadata: {}
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  version: '0'
138
138
  requirements: []
139
139
  rubyforge_project:
140
- rubygems_version: 2.2.0
140
+ rubygems_version: 2.2.2
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Import tabular data into data models
@@ -148,3 +148,4 @@ test_files:
148
148
  - spec/support/active_record/schema.rb
149
149
  - spec/support/employee_importer.rb
150
150
  - spec/support/spreadsheet.rb
151
+ has_rdoc: