active_report 5.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek +1 -0
- data/README.md +3 -0
- data/active_report.gemspec +5 -7
- data/lib/active_report/array.rb +20 -14
- data/lib/active_report/base.rb +1 -1
- data/lib/active_report/hash.rb +18 -9
- data/lib/active_report/record.rb +19 -8
- data/lib/active_report/version.rb +1 -1
- data/lib/generators/active_report/install_generator.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9248db55a8c0da20b43723561304941333dfacf0deb7b5cc4ed65a0659bf66c4
|
4
|
+
data.tar.gz: f6e1b36abe1fb1d2795961603f82eafed5bf2d8ba062226906e6290003287a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d71166d364d08cb17e080fd9e8902d88a4f3fb284d34283d017f94dcfbbde918bc92d672e62629506edd988486de7eb4f631dc4be2c37f4302be111b67bee2d
|
7
|
+
data.tar.gz: ecf4a0724128f3a7db634e32c05422066b65d5af0dfd60cf1f875a3222f52df41379a6bc81f7167562920c6ad06ccf38d907a5f4b5d05478ff7ec91a6084f77d
|
data/.reek
CHANGED
data/README.md
CHANGED
@@ -50,6 +50,7 @@ end
|
|
50
50
|
**Options:**
|
51
51
|
* headers: column titles of CSV data
|
52
52
|
* options: CSV options to be use on generation
|
53
|
+
* stream: generate an enumerator
|
53
54
|
|
54
55
|
```ruby
|
55
56
|
@list = [
|
@@ -82,6 +83,7 @@ ActiveReport::Array.import('sample.csv', headers: ['ID', 'Task', 'Completed'], o
|
|
82
83
|
* except: keys of pairs not to be used on generation
|
83
84
|
* headers: column titles of CSV data
|
84
85
|
* options: CSV options to be use on generation
|
86
|
+
* stream: generate an enumerator
|
85
87
|
|
86
88
|
```ruby
|
87
89
|
@list = [
|
@@ -116,6 +118,7 @@ ActiveReport::Hash.import('sample.csv', except: :completed, headers: ['ID', 'Tas
|
|
116
118
|
* except: columns not to be used on generation
|
117
119
|
* headers: column titles of CSV data
|
118
120
|
* options: CSV options to be use on generation
|
121
|
+
* stream: generate an enumerator
|
119
122
|
|
120
123
|
```ruby
|
121
124
|
@list = [
|
data/active_report.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
6
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
5
|
require 'active_report/version'
|
8
6
|
|
@@ -28,12 +26,12 @@ Gem::Specification.new do |spec|
|
|
28
26
|
spec.add_runtime_dependency 'activerecord-import'
|
29
27
|
|
30
28
|
spec.add_development_dependency 'bundler'
|
31
|
-
spec.add_development_dependency 'rake'
|
32
|
-
spec.add_development_dependency 'rspec'
|
33
|
-
spec.add_development_dependency 'sqlite3'
|
34
29
|
spec.add_development_dependency 'database_cleaner'
|
35
|
-
spec.add_development_dependency 'generator_spec'
|
36
30
|
spec.add_development_dependency 'fasterer'
|
31
|
+
spec.add_development_dependency 'generator_spec'
|
32
|
+
spec.add_development_dependency 'rake'
|
37
33
|
spec.add_development_dependency 'reek'
|
34
|
+
spec.add_development_dependency 'rspec'
|
38
35
|
spec.add_development_dependency 'rubocop'
|
36
|
+
spec.add_development_dependency 'sqlite3'
|
39
37
|
end
|
data/lib/active_report/array.rb
CHANGED
@@ -2,37 +2,43 @@
|
|
2
2
|
|
3
3
|
class ActiveReport::Array < ActiveReport::Base
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(data, headers: nil, options: {})
|
8
|
-
@data = data
|
5
|
+
def initialize(datum, headers: nil, options: {}, stream: false)
|
6
|
+
@datum = datum
|
9
7
|
@headers = headers
|
10
8
|
@options = csv_options.merge(options)
|
9
|
+
@stream = stream
|
11
10
|
end
|
12
11
|
|
13
|
-
def self.export(
|
14
|
-
klass = new(
|
12
|
+
def self.export(datum, headers: nil, options: {}, stream: false)
|
13
|
+
klass = new(datum, headers: headers, options: options, stream: stream)
|
15
14
|
klass.export
|
16
15
|
end
|
17
16
|
|
18
|
-
def self.import(
|
19
|
-
klass = new(
|
17
|
+
def self.import(datum, headers: nil, options: {})
|
18
|
+
klass = new(datum, headers: headers, options: options)
|
20
19
|
klass.import
|
21
20
|
end
|
22
21
|
|
23
22
|
def export
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
@datum = munge_first(@datum)
|
24
|
+
|
25
|
+
if @stream == true
|
26
|
+
Enumerator.new do |csv|
|
27
|
+
csv << @headers unless @headers.nil?
|
28
|
+
@datum.each { |row| csv << row }
|
29
|
+
end
|
30
|
+
else
|
31
|
+
CSV.generate(@options) do |csv|
|
32
|
+
csv << @headers unless @headers.nil?
|
33
|
+
@datum.each { |row| csv << row }
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
38
|
def import
|
33
39
|
array = merge(@headers)
|
34
40
|
|
35
|
-
CSV.foreach(@
|
41
|
+
CSV.foreach(@datum, @options) do |row|
|
36
42
|
row = encode_to_utf8(row) if csv_force_encoding?
|
37
43
|
array.push(row)
|
38
44
|
end
|
data/lib/active_report/base.rb
CHANGED
data/lib/active_report/hash.rb
CHANGED
@@ -2,20 +2,21 @@
|
|
2
2
|
|
3
3
|
class ActiveReport::Hash < ActiveReport::Base
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(datum, only: nil, except: nil, headers: nil, options: {})
|
5
|
+
def initialize(datum, only: nil, except: nil, headers: nil, options: {}, stream: false)
|
8
6
|
@datum = datum
|
9
7
|
@only = munge(only)
|
10
8
|
@except = munge(except)
|
11
9
|
@headers = headers
|
12
10
|
@options = csv_options.merge(options)
|
11
|
+
@stream = stream
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
# rubocop:disable Metrics/LineLength
|
15
|
+
def self.export(datum, only: nil, except: nil, headers: nil, options: {}, stream: false)
|
16
|
+
klass = new(datum, only: only, except: except, headers: headers, options: options, stream: stream)
|
17
17
|
klass.export
|
18
18
|
end
|
19
|
+
# rubocop:enable Metrics/LineLength
|
19
20
|
|
20
21
|
def self.import(datum, only: nil, except: nil, headers: nil, options: {})
|
21
22
|
klass = new(datum, only: only, except: except, headers: headers, options: options)
|
@@ -24,10 +25,18 @@ class ActiveReport::Hash < ActiveReport::Base
|
|
24
25
|
|
25
26
|
def export
|
26
27
|
@datum = munge(@datum)
|
28
|
+
@headers = (@headers || filter_humanize_keys(@datum))
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
if @stream == true
|
31
|
+
Enumerator.new do |csv|
|
32
|
+
csv << @headers
|
33
|
+
@data.each { |row| csv << filter_values(row) }
|
34
|
+
end
|
35
|
+
else
|
36
|
+
CSV.generate(@options) do |csv|
|
37
|
+
csv << @headers
|
38
|
+
@datum.each { |row| csv << filter_values(row) }
|
39
|
+
end
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
@@ -42,7 +51,7 @@ class ActiveReport::Hash < ActiveReport::Base
|
|
42
51
|
@headers = data
|
43
52
|
else
|
44
53
|
subdata = {}
|
45
|
-
@headers.
|
54
|
+
@headers.each_with_index { |header, idx| subdata[header.to_s] = data[idx] }
|
46
55
|
filter(subdata)
|
47
56
|
array.push(subdata)
|
48
57
|
end
|
data/lib/active_report/record.rb
CHANGED
@@ -9,19 +9,22 @@ class ActiveReport::Record < ActiveReport::Base
|
|
9
9
|
|
10
10
|
attr_accessor :datum, :model, :only, :except, :headers, :options
|
11
11
|
|
12
|
-
|
12
|
+
# rubocop:disable Metrics/LineLength
|
13
|
+
def initialize(datum, model: nil, only: nil, except: nil, headers: nil, options: {}, stream: false)
|
13
14
|
@datum = datum
|
14
15
|
@model = model
|
15
16
|
@only = munge(only)
|
16
17
|
@except = munge(except)
|
17
18
|
@headers = headers
|
18
19
|
@options = csv_options.merge(options)
|
20
|
+
@stream = stream
|
19
21
|
end
|
20
22
|
|
21
|
-
def self.export(datum, only: nil, except: nil, headers: nil, options: {})
|
22
|
-
klass = new(datum, only: only, except: except, headers: headers, options: options)
|
23
|
+
def self.export(datum, only: nil, except: nil, headers: nil, options: {}, stream: false)
|
24
|
+
klass = new(datum, only: only, except: except, headers: headers, options: options, stream: stream)
|
23
25
|
klass.export
|
24
26
|
end
|
27
|
+
# rubocop:enable Metrics/LineLength
|
25
28
|
|
26
29
|
def self.import(datum, only: nil, except: nil, headers: nil, options: {}, model: nil)
|
27
30
|
klass = new(datum, only: only, except: except, headers: headers, options: options, model: model)
|
@@ -37,10 +40,18 @@ class ActiveReport::Record < ActiveReport::Base
|
|
37
40
|
|
38
41
|
@only.map!(&:to_s)
|
39
42
|
@except.map!(&:to_s)
|
43
|
+
@headers = (@headers || filter_humanize_keys(@datum))
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
if @stream == true
|
46
|
+
Enumerator.new do |csv|
|
47
|
+
csv << @headers
|
48
|
+
@data.each { |row| csv << filter_values(row) }
|
49
|
+
end
|
50
|
+
else
|
51
|
+
CSV.generate(@options) do |csv|
|
52
|
+
csv << @headers
|
53
|
+
@datum.each { |row| csv << filter_values(row) }
|
54
|
+
end
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
@@ -54,10 +65,10 @@ class ActiveReport::Record < ActiveReport::Base
|
|
54
65
|
@datum = munge(@datum)
|
55
66
|
|
56
67
|
records = []
|
57
|
-
@datum.
|
68
|
+
@datum.each do |data|
|
58
69
|
params = {}
|
59
70
|
|
60
|
-
data.
|
71
|
+
data.each do |key, value|
|
61
72
|
key = key.to_s.downcase.gsub(/ |-/, '_').to_sym
|
62
73
|
params[key] = value
|
63
74
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rails/generators'
|
4
4
|
|
5
5
|
class ActiveReport::InstallGenerator < Rails::Generators::Base
|
6
|
-
source_root File.expand_path('
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
7
|
|
8
8
|
def copy_initializer_file
|
9
9
|
copy_file('install.rb', 'config/initializers/active_report.rb')
|
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.
|
4
|
+
version: 5.2.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:
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: database_cleaner
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: fasterer
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: generator_spec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: reek
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rubocop
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: sqlite3
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -218,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
218
|
version: '0'
|
219
219
|
requirements: []
|
220
220
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.7.
|
221
|
+
rubygems_version: 2.7.6
|
222
222
|
signing_key:
|
223
223
|
specification_version: 4
|
224
224
|
summary: Gem for exporting/importing ruby objects to flat files vice versa.
|