lite-report 1.0.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +72 -69
- data/README.md +27 -0
- data/lib/lite/report.rb +1 -1
- data/lib/lite/report/exporter.rb +42 -0
- data/lib/lite/report/record.rb +1 -1
- data/lib/lite/report/version.rb +1 -1
- data/lite-report.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c47012894f22e7cb6329fd29cd11d674436a26e0721042f92f8686827854ff2
|
4
|
+
data.tar.gz: 5bc35bc9c3f4604121aeb9a9fe519a582f4da4ed5aa7aed0afbd64e8fba5591d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb991fc839a2287a65de08bc70c3e44cc59a003618a2ef4db6eb2f05ece1e028c12ab71c86f6242c8423a723e6dd826414d2eb123fcd8af6b853146672aff5a9
|
7
|
+
data.tar.gz: b957984a667255674fd66e2122e2c813b515cbe04daff7c5e0227eb74c44c3c0425024945012a857901b92e3131277c7774e812a04f8e59802afb4d52c25672a
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.1.0] - 2021-01-06
|
10
|
+
### Added
|
11
|
+
- Added Exporter helper class
|
12
|
+
- Added rubocop-rake linter
|
13
|
+
|
9
14
|
## [1.0.6] - 2020-10-10
|
10
15
|
### Added
|
11
16
|
- Added improved Ruby 2.7 support
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-report (1.0
|
4
|
+
lite-report (1.1.0)
|
5
5
|
activerecord
|
6
6
|
activerecord-import
|
7
7
|
deep_pluck
|
@@ -9,32 +9,32 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (6.0
|
13
|
-
actionview (= 6.0
|
14
|
-
activesupport (= 6.0
|
15
|
-
rack (~> 2.0, >= 2.0.
|
12
|
+
actionpack (6.1.0)
|
13
|
+
actionview (= 6.1.0)
|
14
|
+
activesupport (= 6.1.0)
|
15
|
+
rack (~> 2.0, >= 2.0.9)
|
16
16
|
rack-test (>= 0.6.3)
|
17
17
|
rails-dom-testing (~> 2.0)
|
18
18
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
19
|
-
actionview (6.0
|
20
|
-
activesupport (= 6.0
|
19
|
+
actionview (6.1.0)
|
20
|
+
activesupport (= 6.1.0)
|
21
21
|
builder (~> 3.1)
|
22
22
|
erubi (~> 1.4)
|
23
23
|
rails-dom-testing (~> 2.0)
|
24
24
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
25
|
-
activemodel (6.0
|
26
|
-
activesupport (= 6.0
|
27
|
-
activerecord (6.0
|
28
|
-
activemodel (= 6.0
|
29
|
-
activesupport (= 6.0
|
30
|
-
activerecord-import (1.0.
|
25
|
+
activemodel (6.1.0)
|
26
|
+
activesupport (= 6.1.0)
|
27
|
+
activerecord (6.1.0)
|
28
|
+
activemodel (= 6.1.0)
|
29
|
+
activesupport (= 6.1.0)
|
30
|
+
activerecord-import (1.0.7)
|
31
31
|
activerecord (>= 3.2)
|
32
|
-
activesupport (6.0
|
32
|
+
activesupport (6.1.0)
|
33
33
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
34
|
-
i18n (>=
|
35
|
-
minitest (
|
36
|
-
tzinfo (~>
|
37
|
-
zeitwerk (~> 2.
|
34
|
+
i18n (>= 1.6, < 2)
|
35
|
+
minitest (>= 5.1)
|
36
|
+
tzinfo (~> 2.0)
|
37
|
+
zeitwerk (~> 2.3)
|
38
38
|
ast (2.4.1)
|
39
39
|
builder (3.2.4)
|
40
40
|
colorize (0.8.1)
|
@@ -46,30 +46,31 @@ GEM
|
|
46
46
|
pluck_all (>= 1.2.3)
|
47
47
|
rails_compatibility (>= 0.0.1)
|
48
48
|
diff-lcs (1.4.4)
|
49
|
-
erubi (1.
|
49
|
+
erubi (1.10.0)
|
50
50
|
fasterer (0.8.3)
|
51
51
|
colorize (~> 0.7)
|
52
52
|
ruby_parser (>= 3.14.1)
|
53
53
|
generator_spec (0.9.4)
|
54
54
|
activesupport (>= 3.0.0)
|
55
55
|
railties (>= 3.0.0)
|
56
|
-
i18n (1.8.
|
56
|
+
i18n (1.8.7)
|
57
57
|
concurrent-ruby (~> 1.0)
|
58
|
-
loofah (2.
|
58
|
+
loofah (2.8.0)
|
59
59
|
crass (~> 1.0.2)
|
60
60
|
nokogiri (>= 1.5.9)
|
61
61
|
method_source (1.0.0)
|
62
|
-
mini_portile2 (2.
|
63
|
-
minitest (5.14.
|
64
|
-
nokogiri (1.
|
65
|
-
mini_portile2 (~> 2.
|
66
|
-
|
67
|
-
|
62
|
+
mini_portile2 (2.5.0)
|
63
|
+
minitest (5.14.3)
|
64
|
+
nokogiri (1.11.1)
|
65
|
+
mini_portile2 (~> 2.5.0)
|
66
|
+
racc (~> 1.4)
|
67
|
+
parallel (1.20.1)
|
68
|
+
parser (3.0.0.0)
|
68
69
|
ast (~> 2.4.1)
|
69
|
-
pluck_all (2.
|
70
|
+
pluck_all (2.2.1)
|
70
71
|
activesupport (>= 3.0.0)
|
71
|
-
|
72
|
-
|
72
|
+
rails_compatibility (>= 0.0.2)
|
73
|
+
racc (1.5.2)
|
73
74
|
rack (2.2.3)
|
74
75
|
rack-test (1.1.0)
|
75
76
|
rack (>= 1.0, < 3)
|
@@ -80,69 +81,70 @@ GEM
|
|
80
81
|
loofah (~> 2.3)
|
81
82
|
rails_compatibility (0.0.2)
|
82
83
|
activerecord (>= 3)
|
83
|
-
railties (6.0
|
84
|
-
actionpack (= 6.0
|
85
|
-
activesupport (= 6.0
|
84
|
+
railties (6.1.0)
|
85
|
+
actionpack (= 6.1.0)
|
86
|
+
activesupport (= 6.1.0)
|
86
87
|
method_source
|
87
88
|
rake (>= 0.8.7)
|
88
|
-
thor (
|
89
|
+
thor (~> 1.0)
|
89
90
|
rainbow (3.0.0)
|
90
|
-
rake (13.0.
|
91
|
-
ransack (2.
|
92
|
-
activerecord (>= 5.2.
|
93
|
-
activesupport (>= 5.2.
|
91
|
+
rake (13.0.3)
|
92
|
+
ransack (2.4.1)
|
93
|
+
activerecord (>= 5.2.4)
|
94
|
+
activesupport (>= 5.2.4)
|
94
95
|
i18n
|
95
|
-
|
96
|
-
regexp_parser (1.8.1)
|
96
|
+
regexp_parser (2.0.3)
|
97
97
|
rexml (3.2.4)
|
98
|
-
rspec (3.
|
99
|
-
rspec-core (~> 3.
|
100
|
-
rspec-expectations (~> 3.
|
101
|
-
rspec-mocks (~> 3.
|
102
|
-
rspec-core (3.
|
103
|
-
rspec-support (~> 3.
|
104
|
-
rspec-expectations (3.
|
98
|
+
rspec (3.10.0)
|
99
|
+
rspec-core (~> 3.10.0)
|
100
|
+
rspec-expectations (~> 3.10.0)
|
101
|
+
rspec-mocks (~> 3.10.0)
|
102
|
+
rspec-core (3.10.1)
|
103
|
+
rspec-support (~> 3.10.0)
|
104
|
+
rspec-expectations (3.10.1)
|
105
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
106
|
-
rspec-support (~> 3.
|
107
|
-
rspec-mocks (3.
|
106
|
+
rspec-support (~> 3.10.0)
|
107
|
+
rspec-mocks (3.10.1)
|
108
108
|
diff-lcs (>= 1.2.0, < 2.0)
|
109
|
-
rspec-support (~> 3.
|
110
|
-
rspec-rails (4.0.
|
109
|
+
rspec-support (~> 3.10.0)
|
110
|
+
rspec-rails (4.0.2)
|
111
111
|
actionpack (>= 4.2)
|
112
112
|
activesupport (>= 4.2)
|
113
113
|
railties (>= 4.2)
|
114
|
-
rspec-core (~> 3.
|
115
|
-
rspec-expectations (~> 3.
|
116
|
-
rspec-mocks (~> 3.
|
117
|
-
rspec-support (~> 3.
|
118
|
-
rspec-support (3.
|
119
|
-
rubocop (
|
114
|
+
rspec-core (~> 3.10)
|
115
|
+
rspec-expectations (~> 3.10)
|
116
|
+
rspec-mocks (~> 3.10)
|
117
|
+
rspec-support (~> 3.10)
|
118
|
+
rspec-support (3.10.1)
|
119
|
+
rubocop (1.7.0)
|
120
120
|
parallel (~> 1.10)
|
121
121
|
parser (>= 2.7.1.5)
|
122
122
|
rainbow (>= 2.2.2, < 4.0)
|
123
|
-
regexp_parser (>= 1.8)
|
123
|
+
regexp_parser (>= 1.8, < 3.0)
|
124
124
|
rexml
|
125
|
-
rubocop-ast (>=
|
125
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
126
126
|
ruby-progressbar (~> 1.7)
|
127
127
|
unicode-display_width (>= 1.4.0, < 2.0)
|
128
|
-
rubocop-ast (
|
128
|
+
rubocop-ast (1.4.0)
|
129
129
|
parser (>= 2.7.1.5)
|
130
|
-
rubocop-performance (1.
|
131
|
-
rubocop (>= 0.
|
130
|
+
rubocop-performance (1.9.2)
|
131
|
+
rubocop (>= 0.90.0, < 2.0)
|
132
132
|
rubocop-ast (>= 0.4.0)
|
133
|
-
rubocop-
|
134
|
-
rubocop
|
135
|
-
|
133
|
+
rubocop-rake (0.5.1)
|
134
|
+
rubocop
|
135
|
+
rubocop-rspec (2.1.0)
|
136
|
+
rubocop (~> 1.0)
|
137
|
+
rubocop-ast (>= 1.1.0)
|
138
|
+
ruby-progressbar (1.11.0)
|
136
139
|
ruby_parser (3.15.0)
|
137
140
|
sexp_processor (~> 4.9)
|
138
141
|
sexp_processor (4.15.1)
|
139
142
|
sqlite3 (1.4.2)
|
140
143
|
thor (1.0.1)
|
141
|
-
|
142
|
-
|
143
|
-
thread_safe (~> 0.1)
|
144
|
+
tzinfo (2.0.4)
|
145
|
+
concurrent-ruby (~> 1.0)
|
144
146
|
unicode-display_width (1.7.0)
|
145
|
-
zeitwerk (2.4.
|
147
|
+
zeitwerk (2.4.2)
|
146
148
|
|
147
149
|
PLATFORMS
|
148
150
|
ruby
|
@@ -159,6 +161,7 @@ DEPENDENCIES
|
|
159
161
|
rspec-rails
|
160
162
|
rubocop
|
161
163
|
rubocop-performance
|
164
|
+
rubocop-rake
|
162
165
|
rubocop-rspec
|
163
166
|
sqlite3
|
164
167
|
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ Or install it yourself as:
|
|
31
31
|
* [Array](#array)
|
32
32
|
* [Hash](#hash)
|
33
33
|
* [Record](#record)
|
34
|
+
* [Exporter](#exporter)
|
34
35
|
* [Stream](#stream)
|
35
36
|
* [Port](#port)
|
36
37
|
|
@@ -144,6 +145,32 @@ Lite::Report::Record.import(
|
|
144
145
|
)
|
145
146
|
```
|
146
147
|
|
148
|
+
## Exporter
|
149
|
+
|
150
|
+
Use exporters to filter, manipulate, and prepare data before final exportation.
|
151
|
+
These are very helpful when working with complex datasets.
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
class LimitedExporter < Lite::Report::Exporter
|
155
|
+
|
156
|
+
private
|
157
|
+
|
158
|
+
def serialize(record)
|
159
|
+
{
|
160
|
+
'Id' => record.id,
|
161
|
+
'Name' => "#{record.first_name} #{record.last_name}",
|
162
|
+
'Speed' => record.speed.ceil,
|
163
|
+
'Date' => record.to_s(:short)
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
raw_data = User.where(age: 20..29)
|
170
|
+
limited_data = LimitedExporter.call(raw_data)
|
171
|
+
Lite::Report::Hash.export(limited_data)
|
172
|
+
```
|
173
|
+
|
147
174
|
## Stream
|
148
175
|
|
149
176
|
Stream is great option for preventing browser timeouts of downloading large CSV files by chunking
|
data/lib/lite/report.rb
CHANGED
@@ -7,7 +7,7 @@ require 'lite/report/version'
|
|
7
7
|
require "lite/report/helpers/#{file_name}"
|
8
8
|
end
|
9
9
|
|
10
|
-
%w[configuration base array hash record].each do |file_name|
|
10
|
+
%w[configuration base array hash record exporter].each do |file_name|
|
11
11
|
require "lite/report/#{file_name}"
|
12
12
|
end
|
13
13
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Lite::Report::Exporter
|
4
|
+
|
5
|
+
class NotImplementedError < StandardError; end
|
6
|
+
|
7
|
+
attr_reader :records
|
8
|
+
|
9
|
+
def initialize(records)
|
10
|
+
@records = records
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def call(records)
|
16
|
+
instance = new(records)
|
17
|
+
instance.call
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def call
|
23
|
+
results = []
|
24
|
+
|
25
|
+
if records.respond_to?(:find_each)
|
26
|
+
records.find_each { |record| results << serialize(record) }
|
27
|
+
elsif records.respond_to?(:each)
|
28
|
+
records.each { |record| results << serialize(record) }
|
29
|
+
else
|
30
|
+
results << serialize(records)
|
31
|
+
end
|
32
|
+
|
33
|
+
results
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def serialize(record)
|
39
|
+
raise NotImplementedError
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/lite/report/record.rb
CHANGED
@@ -43,7 +43,7 @@ class Lite::Report::Record < Lite::Report::Base
|
|
43
43
|
columns = class_columns(@data)
|
44
44
|
@data = @data.result if ransack_class?(@data)
|
45
45
|
@data = @data.deep_pluck(*columns)
|
46
|
-
@data = [@data]
|
46
|
+
@data = [@data] if !@data.respond_to?(:each) || !@data.is_a?(Array)
|
47
47
|
end
|
48
48
|
|
49
49
|
def generate_export!
|
data/lib/lite/report/version.rb
CHANGED
data/lite-report.gemspec
CHANGED
@@ -51,6 +51,7 @@ Gem::Specification.new do |spec|
|
|
51
51
|
spec.add_development_dependency 'rspec-rails'
|
52
52
|
spec.add_development_dependency 'rubocop'
|
53
53
|
spec.add_development_dependency 'rubocop-performance'
|
54
|
+
spec.add_development_dependency 'rubocop-rake'
|
54
55
|
spec.add_development_dependency 'rubocop-rspec'
|
55
56
|
spec.add_development_dependency 'sqlite3'
|
56
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.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:
|
11
|
+
date: 2021-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-rake
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
- !ruby/object:Gem::Dependency
|
196
210
|
name: rubocop-rspec
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -249,6 +263,7 @@ files:
|
|
249
263
|
- lib/lite/report/array.rb
|
250
264
|
- lib/lite/report/base.rb
|
251
265
|
- lib/lite/report/configuration.rb
|
266
|
+
- lib/lite/report/exporter.rb
|
252
267
|
- lib/lite/report/hash.rb
|
253
268
|
- lib/lite/report/helpers/converters.rb
|
254
269
|
- lib/lite/report/helpers/encoders.rb
|
@@ -279,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
294
|
- !ruby/object:Gem::Version
|
280
295
|
version: '0'
|
281
296
|
requirements: []
|
282
|
-
rubygems_version: 3.
|
297
|
+
rubygems_version: 3.2.4
|
283
298
|
signing_key:
|
284
299
|
specification_version: 4
|
285
300
|
summary: Import and export Ruby and Rails objects to flat files and vice versa
|