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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b94708f3ef60f8780c0444e9ea75767073b8c6e93ca3ec2259d3d9fab20f4e3f
4
- data.tar.gz: c47f0fcc4a55fd85b52d479fab6b79f66c49ef7644fbd2eca93e1638142e2437
3
+ metadata.gz: 6c47012894f22e7cb6329fd29cd11d674436a26e0721042f92f8686827854ff2
4
+ data.tar.gz: 5bc35bc9c3f4604121aeb9a9fe519a582f4da4ed5aa7aed0afbd64e8fba5591d
5
5
  SHA512:
6
- metadata.gz: ec0aaa4561df1d5ed44c48897aefc7580769936e6ece768679321c8208d43b1def9308982e9f3320b040bed9d2a98c5641ae8e381524c2b1a8d7c3e7a7b1eda4
7
- data.tar.gz: 278459ea22c634e0e38222af6b55031a4d02ed7831eb1f67ac625a136ee88e4e9543990c6b67266451e4f22928a29e76df81f4b4ca28c1a1f621ed9f1adbc9b7
6
+ metadata.gz: fb991fc839a2287a65de08bc70c3e44cc59a003618a2ef4db6eb2f05ece1e028c12ab71c86f6242c8423a723e6dd826414d2eb123fcd8af6b853146672aff5a9
7
+ data.tar.gz: b957984a667255674fd66e2122e2c813b515cbe04daff7c5e0227eb74c44c3c0425024945012a857901b92e3131277c7774e812a04f8e59802afb4d52c25672a
@@ -1,5 +1,6 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-rake
3
4
  - rubocop-rspec
4
5
  AllCops:
5
6
  TargetRubyVersion: 2.7
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-report (1.0.6)
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.3.4)
13
- actionview (= 6.0.3.4)
14
- activesupport (= 6.0.3.4)
15
- rack (~> 2.0, >= 2.0.8)
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.3.4)
20
- activesupport (= 6.0.3.4)
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.3.4)
26
- activesupport (= 6.0.3.4)
27
- activerecord (6.0.3.4)
28
- activemodel (= 6.0.3.4)
29
- activesupport (= 6.0.3.4)
30
- activerecord-import (1.0.6)
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.3.4)
32
+ activesupport (6.1.0)
33
33
  concurrent-ruby (~> 1.0, >= 1.0.2)
34
- i18n (>= 0.7, < 2)
35
- minitest (~> 5.1)
36
- tzinfo (~> 1.1)
37
- zeitwerk (~> 2.2, >= 2.2.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.9.0)
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.5)
56
+ i18n (1.8.7)
57
57
  concurrent-ruby (~> 1.0)
58
- loofah (2.7.0)
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.4.0)
63
- minitest (5.14.2)
64
- nokogiri (1.10.10)
65
- mini_portile2 (~> 2.4.0)
66
- parallel (1.19.2)
67
- parser (2.7.2.0)
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.0.4)
70
+ pluck_all (2.2.1)
70
71
  activesupport (>= 3.0.0)
71
- polyamorous (2.3.2)
72
- activerecord (>= 5.2.1)
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.3.4)
84
- actionpack (= 6.0.3.4)
85
- activesupport (= 6.0.3.4)
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 (>= 0.20.3, < 2.0)
89
+ thor (~> 1.0)
89
90
  rainbow (3.0.0)
90
- rake (13.0.1)
91
- ransack (2.3.2)
92
- activerecord (>= 5.2.1)
93
- activesupport (>= 5.2.1)
91
+ rake (13.0.3)
92
+ ransack (2.4.1)
93
+ activerecord (>= 5.2.4)
94
+ activesupport (>= 5.2.4)
94
95
  i18n
95
- polyamorous (= 2.3.2)
96
- regexp_parser (1.8.1)
96
+ regexp_parser (2.0.3)
97
97
  rexml (3.2.4)
98
- rspec (3.9.0)
99
- rspec-core (~> 3.9.0)
100
- rspec-expectations (~> 3.9.0)
101
- rspec-mocks (~> 3.9.0)
102
- rspec-core (3.9.3)
103
- rspec-support (~> 3.9.3)
104
- rspec-expectations (3.9.2)
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.9.0)
107
- rspec-mocks (3.9.1)
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.9.0)
110
- rspec-rails (4.0.1)
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.9)
115
- rspec-expectations (~> 3.9)
116
- rspec-mocks (~> 3.9)
117
- rspec-support (~> 3.9)
118
- rspec-support (3.9.3)
119
- rubocop (0.93.0)
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 (>= 0.6.0)
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 (0.7.1)
128
+ rubocop-ast (1.4.0)
129
129
  parser (>= 2.7.1.5)
130
- rubocop-performance (1.8.1)
131
- rubocop (>= 0.87.0)
130
+ rubocop-performance (1.9.2)
131
+ rubocop (>= 0.90.0, < 2.0)
132
132
  rubocop-ast (>= 0.4.0)
133
- rubocop-rspec (1.43.2)
134
- rubocop (~> 0.87)
135
- ruby-progressbar (1.10.1)
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
- thread_safe (0.3.6)
142
- tzinfo (1.2.7)
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.0)
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
@@ -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
@@ -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] unless @data.is_a?(Array)
46
+ @data = [@data] if !@data.respond_to?(:each) || !@data.is_a?(Array)
47
47
  end
48
48
 
49
49
  def generate_export!
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Report
5
5
 
6
- VERSION ||= '1.0.6'
6
+ VERSION ||= '1.1.0'
7
7
 
8
8
  end
9
9
  end
@@ -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.6
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: 2020-10-11 00:00:00.000000000 Z
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.1.4
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