active_report 5.0.1 → 5.1.0

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
- SHA1:
3
- metadata.gz: cf67aa7fef1c9755c416bc3b320644ffc44f26c1
4
- data.tar.gz: 1df2df707ad6d44f3499de85bea0f5dcb8c04fc1
2
+ SHA256:
3
+ metadata.gz: 62f3910d3aa4740c3e5bc3bad0f0aef0dcc206b383111a47a5cfaeb56b90f2c2
4
+ data.tar.gz: 0abfb5b3f2c2d39611e6a596bda3d82c7f2767cdfb9fa970215575cad2a9a2f0
5
5
  SHA512:
6
- metadata.gz: 2fe100e1f71059948f9b9f52b5bcc0507b20edc8ac59495529882c291ecc4fd0711605466f57581b3dd4d1f9a726693a5a269050f775697d08ae6f03ab43e108
7
- data.tar.gz: '085dc109f3979eca71e2a1d87232d70af1070b6a9d1bc75eac35cd277d4669b93d7d1d5269875dc6f0fad112bb2e9189da20729a26e7e7ffe22cd51c2252eb5b'
6
+ metadata.gz: c70f6edc36e88b5b7fa670985af6d8ecdb4416fc4f2f94712ba803649028bc61f72d84cf5e5f81aff510c18a1a630628a1bb890e21151fa100779e302666fb81
7
+ data.tar.gz: b9d850afcadc91dca8a7fa4529c6317d8ca373f61606b8b69cfc22b3e39783109bbfac89cf114c0c9824eda7787e03e6a804e94069957786d21d3ce60c66eb09
data/README.md CHANGED
@@ -38,6 +38,8 @@ Or install it yourself as:
38
38
  ActiveReport.configure do |config|
39
39
  config.csv_force_encoding = true
40
40
  config.csv_options = { encoding: 'UTF-8' }
41
+ config.import_adapter = 'mysql2_adapter'
42
+ config.import_options = { validate: false, on_duplicate_key_ignore: true }
41
43
  end
42
44
  ```
43
45
 
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = %w[lib support]
26
26
 
27
27
  spec.add_runtime_dependency 'activerecord'
28
+ spec.add_runtime_dependency 'activerecord-import'
28
29
 
29
30
  spec.add_development_dependency 'bundler'
30
31
  spec.add_development_dependency 'rake'
@@ -12,6 +12,14 @@ class ActiveReport::Base
12
12
  ActiveReport.configuration.csv_force_encoding
13
13
  end
14
14
 
15
+ def import_adapter
16
+ ActiveReport.configuration.import_adapter
17
+ end
18
+
19
+ def import_options
20
+ ActiveReport.configuration.import_options
21
+ end
22
+
15
23
  def self.evaluate(value = true)
16
24
  @@evaluate = value
17
25
  self
@@ -3,11 +3,13 @@
3
3
  module ActiveReport
4
4
  class Configuration
5
5
 
6
- attr_accessor :csv_force_encoding, :csv_options
6
+ attr_accessor :csv_force_encoding, :csv_options, :import_adapter, :import_options
7
7
 
8
8
  def initialize
9
9
  @csv_force_encoding = true
10
10
  @csv_options = { encoding: 'UTF-8' }
11
+ @import_adapter = 'mysql2_adapter'
12
+ @import_options = { validate: false, on_duplicate_key_ignore: true }
11
13
  end
12
14
 
13
15
  end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'activerecord-import'
4
+ require 'activerecord-import/base'
5
+ require "activerecord-import/active_record/adapters/#{ActiveReport.configuration.import_adapter}"
3
6
  require 'json'
4
7
 
5
8
  class ActiveReport::Record < ActiveReport::Base
@@ -50,6 +53,7 @@ class ActiveReport::Record < ActiveReport::Base
50
53
  @datum = ActiveReport::Hash.import(@datum, headers: @headers, options: @options)
51
54
  @datum = munge(@datum)
52
55
 
56
+ records = []
53
57
  @datum.lazy.each do |data|
54
58
  params = {}
55
59
 
@@ -60,8 +64,10 @@ class ActiveReport::Record < ActiveReport::Base
60
64
 
61
65
  filter(params)
62
66
  params.delete(:id)
63
- @model.create(params)
67
+ records << params
64
68
  end
69
+
70
+ @model.import(records, import_options)
65
71
  end
66
72
 
67
73
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveReport
4
- VERSION ||= '5.0.1'
4
+ VERSION ||= '5.1.0'
5
5
  end
@@ -3,4 +3,6 @@
3
3
  ActiveReport.configure do |config|
4
4
  config.csv_force_encoding = true
5
5
  config.csv_options = { encoding: 'UTF-8' }
6
+ config.import_adapter = 'mysql2_adapter'
7
+ config.import_options = { validate: false, on_duplicate_key_ignore: true }
6
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-14 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord-import
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
218
  version: '0'
205
219
  requirements: []
206
220
  rubyforge_project:
207
- rubygems_version: 2.6.14
221
+ rubygems_version: 2.7.3
208
222
  signing_key:
209
223
  specification_version: 4
210
224
  summary: Gem for exporting/importing ruby objects to flat files vice versa.