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 +5 -5
- data/README.md +2 -0
- data/active_report.gemspec +1 -0
- data/lib/active_report/base.rb +8 -0
- data/lib/active_report/configuration.rb +3 -1
- data/lib/active_report/record.rb +7 -1
- data/lib/active_report/version.rb +1 -1
- data/lib/generators/active_report/templates/install.rb +2 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 62f3910d3aa4740c3e5bc3bad0f0aef0dcc206b383111a47a5cfaeb56b90f2c2
|
4
|
+
data.tar.gz: 0abfb5b3f2c2d39611e6a596bda3d82c7f2767cdfb9fa970215575cad2a9a2f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/active_report.gemspec
CHANGED
@@ -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'
|
data/lib/active_report/base.rb
CHANGED
@@ -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
|
data/lib/active_report/record.rb
CHANGED
@@ -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
|
-
|
67
|
+
records << params
|
64
68
|
end
|
69
|
+
|
70
|
+
@model.import(records, import_options)
|
65
71
|
end
|
66
72
|
|
67
73
|
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
|
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-
|
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.
|
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.
|