lite-report 1.0.2 → 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: fec247c1ce8a3f5a03f01b9d389c50be4400c02ec1e4cc8fc2de8092b0d67747
4
- data.tar.gz: 78f4d4b3d9f1557f2c26447ac6223affc786f8938e5d0b442d8c233530051ffb
3
+ metadata.gz: 6c47012894f22e7cb6329fd29cd11d674436a26e0721042f92f8686827854ff2
4
+ data.tar.gz: 5bc35bc9c3f4604121aeb9a9fe519a582f4da4ed5aa7aed0afbd64e8fba5591d
5
5
  SHA512:
6
- metadata.gz: b016454a0f0f3e9eada7b1db8bb0c177b23e85cae65c01f23c024c6ece93b3e741f1a358ab5e0fff845db8c016904dda1c8da2ee5b13756374ca43173915a2e7
7
- data.tar.gz: acb39fcfdd3c6e61482b3ccb789e706c8160e3beadacba090e289a3e7d1225231c490de249ddba1910e83c10bf9463c1adb1e754de6f06636290150acf7f87f0
6
+ metadata.gz: fb991fc839a2287a65de08bc70c3e44cc59a003618a2ef4db6eb2f05ece1e028c12ab71c86f6242c8423a723e6dd826414d2eb123fcd8af6b853146672aff5a9
7
+ data.tar.gz: b957984a667255674fd66e2122e2c813b515cbe04daff7c5e0227eb74c44c3c0425024945012a857901b92e3131277c7774e812a04f8e59802afb4d52c25672a
@@ -1,12 +1,16 @@
1
1
  require:
2
2
  - rubocop-performance
3
+ - rubocop-rake
3
4
  - rubocop-rspec
4
5
  AllCops:
5
- TargetRubyVersion: 2.6
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
6
8
  DisplayCopNames: true
7
9
  DisplayStyleGuide: true
8
- LineLength:
9
- Max: 100
10
+ Gemspec/RequiredRubyVersion:
11
+ Enabled: false
12
+ Layout/EmptyLinesAroundAttributeAccessor:
13
+ Enabled: true
10
14
  Layout/EmptyLinesAroundBlockBody:
11
15
  Exclude:
12
16
  - 'spec/**/**/*'
@@ -14,6 +18,14 @@ Layout/EmptyLinesAroundClassBody:
14
18
  EnforcedStyle: empty_lines_except_namespace
15
19
  Layout/EmptyLinesAroundModuleBody:
16
20
  EnforcedStyle: empty_lines_except_namespace
21
+ Layout/LineLength:
22
+ Max: 100
23
+ Layout/SpaceAroundMethodCallOperator:
24
+ Enabled: true
25
+ Lint/RaiseException:
26
+ Enabled: true
27
+ Lint/StructNewOverride:
28
+ Enabled: true
17
29
  Metrics/BlockLength:
18
30
  Exclude:
19
31
  - 'spec/**/**/*'
@@ -4,6 +4,7 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.5
6
6
  - 2.6
7
+ - 2.7
7
8
  - ruby-head
8
9
  matrix:
9
10
  fast_finish: true
@@ -6,9 +6,30 @@ 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
+
14
+ ## [1.0.6] - 2020-10-10
15
+ ### Added
16
+ - Added improved Ruby 2.7 support
17
+
18
+ ## [1.0.5] - 2020-07-03
19
+ ### Added
20
+ - Added Ruby 2.7 support
21
+
22
+ ## [1.0.4] - 2020-02-11
23
+ ### Changed
24
+ - Fix record instance not generating
25
+
26
+ ## [1.0.3] - 2019-08-24
27
+ ### Changed
28
+ - Fix broken configuration option
29
+
9
30
  ## [1.0.2] - 2019-08-24
10
31
  ### Changed
11
- - Imporved how configuration works
32
+ - Improved how configuration works
12
33
 
13
34
  ## [1.0.1] - 2019-08-15
14
35
  ### Changed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-report (1.0.2)
4
+ lite-report (1.1.0)
5
5
  activerecord
6
6
  activerecord-import
7
7
  deep_pluck
@@ -9,132 +9,142 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionpack (6.0.0)
13
- actionview (= 6.0.0)
14
- activesupport (= 6.0.0)
15
- rack (~> 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.0)
20
- activesupport (= 6.0.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.0)
26
- activesupport (= 6.0.0)
27
- activerecord (6.0.0)
28
- activemodel (= 6.0.0)
29
- activesupport (= 6.0.0)
30
- activerecord-import (1.0.2)
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.0)
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.1, >= 2.1.8)
38
- ast (2.4.0)
39
- builder (3.2.3)
34
+ i18n (>= 1.6, < 2)
35
+ minitest (>= 5.1)
36
+ tzinfo (~> 2.0)
37
+ zeitwerk (~> 2.3)
38
+ ast (2.4.1)
39
+ builder (3.2.4)
40
40
  colorize (0.8.1)
41
- concurrent-ruby (1.1.5)
42
- crass (1.0.4)
43
- database_cleaner (1.7.0)
44
- deep_pluck (1.1.1)
41
+ concurrent-ruby (1.1.7)
42
+ crass (1.0.6)
43
+ database_cleaner (1.8.5)
44
+ deep_pluck (1.1.4)
45
45
  activerecord (>= 3)
46
46
  pluck_all (>= 1.2.3)
47
- diff-lcs (1.3)
48
- erubi (1.8.0)
49
- fasterer (0.6.0)
47
+ rails_compatibility (>= 0.0.1)
48
+ diff-lcs (1.4.4)
49
+ erubi (1.10.0)
50
+ fasterer (0.8.3)
50
51
  colorize (~> 0.7)
51
- ruby_parser (>= 3.13.0)
52
+ ruby_parser (>= 3.14.1)
52
53
  generator_spec (0.9.4)
53
54
  activesupport (>= 3.0.0)
54
55
  railties (>= 3.0.0)
55
- i18n (1.6.0)
56
+ i18n (1.8.7)
56
57
  concurrent-ruby (~> 1.0)
57
- jaro_winkler (1.5.3)
58
- loofah (2.2.3)
58
+ loofah (2.8.0)
59
59
  crass (~> 1.0.2)
60
60
  nokogiri (>= 1.5.9)
61
- method_source (0.9.2)
62
- mini_portile2 (2.4.0)
63
- minitest (5.11.3)
64
- nokogiri (1.10.4)
65
- mini_portile2 (~> 2.4.0)
66
- parallel (1.17.0)
67
- parser (2.6.3.0)
68
- ast (~> 2.4.0)
69
- pluck_all (2.0.4)
61
+ method_source (1.0.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)
69
+ ast (~> 2.4.1)
70
+ pluck_all (2.2.1)
70
71
  activesupport (>= 3.0.0)
71
- polyamorous (2.3.0)
72
- activerecord (>= 5.0)
73
- rack (2.0.7)
72
+ rails_compatibility (>= 0.0.2)
73
+ racc (1.5.2)
74
+ rack (2.2.3)
74
75
  rack-test (1.1.0)
75
76
  rack (>= 1.0, < 3)
76
77
  rails-dom-testing (2.0.3)
77
78
  activesupport (>= 4.2.0)
78
79
  nokogiri (>= 1.6)
79
- rails-html-sanitizer (1.2.0)
80
- loofah (~> 2.2, >= 2.2.2)
81
- railties (6.0.0)
82
- actionpack (= 6.0.0)
83
- activesupport (= 6.0.0)
80
+ rails-html-sanitizer (1.3.0)
81
+ loofah (~> 2.3)
82
+ rails_compatibility (0.0.2)
83
+ activerecord (>= 3)
84
+ railties (6.1.0)
85
+ actionpack (= 6.1.0)
86
+ activesupport (= 6.1.0)
84
87
  method_source
85
88
  rake (>= 0.8.7)
86
- thor (>= 0.20.3, < 2.0)
89
+ thor (~> 1.0)
87
90
  rainbow (3.0.0)
88
- rake (12.3.3)
89
- ransack (2.3.0)
90
- actionpack (>= 5.0)
91
- activerecord (>= 5.0)
92
- activesupport (>= 5.0)
91
+ rake (13.0.3)
92
+ ransack (2.4.1)
93
+ activerecord (>= 5.2.4)
94
+ activesupport (>= 5.2.4)
93
95
  i18n
94
- polyamorous (= 2.3.0)
95
- rspec (3.8.0)
96
- rspec-core (~> 3.8.0)
97
- rspec-expectations (~> 3.8.0)
98
- rspec-mocks (~> 3.8.0)
99
- rspec-core (3.8.2)
100
- rspec-support (~> 3.8.0)
101
- rspec-expectations (3.8.4)
96
+ regexp_parser (2.0.3)
97
+ rexml (3.2.4)
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)
102
105
  diff-lcs (>= 1.2.0, < 2.0)
103
- rspec-support (~> 3.8.0)
104
- rspec-mocks (3.8.1)
106
+ rspec-support (~> 3.10.0)
107
+ rspec-mocks (3.10.1)
105
108
  diff-lcs (>= 1.2.0, < 2.0)
106
- rspec-support (~> 3.8.0)
107
- rspec-rails (3.8.2)
108
- actionpack (>= 3.0)
109
- activesupport (>= 3.0)
110
- railties (>= 3.0)
111
- rspec-core (~> 3.8.0)
112
- rspec-expectations (~> 3.8.0)
113
- rspec-mocks (~> 3.8.0)
114
- rspec-support (~> 3.8.0)
115
- rspec-support (3.8.2)
116
- rubocop (0.74.0)
117
- jaro_winkler (~> 1.5.1)
109
+ rspec-support (~> 3.10.0)
110
+ rspec-rails (4.0.2)
111
+ actionpack (>= 4.2)
112
+ activesupport (>= 4.2)
113
+ railties (>= 4.2)
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)
118
120
  parallel (~> 1.10)
119
- parser (>= 2.6)
121
+ parser (>= 2.7.1.5)
120
122
  rainbow (>= 2.2.2, < 4.0)
123
+ regexp_parser (>= 1.8, < 3.0)
124
+ rexml
125
+ rubocop-ast (>= 1.2.0, < 2.0)
121
126
  ruby-progressbar (~> 1.7)
122
- unicode-display_width (>= 1.4.0, < 1.7)
123
- rubocop-performance (1.4.1)
124
- rubocop (>= 0.71.0)
125
- rubocop-rspec (1.35.0)
126
- rubocop (>= 0.60.0)
127
- ruby-progressbar (1.10.1)
128
- ruby_parser (3.13.1)
127
+ unicode-display_width (>= 1.4.0, < 2.0)
128
+ rubocop-ast (1.4.0)
129
+ parser (>= 2.7.1.5)
130
+ rubocop-performance (1.9.2)
131
+ rubocop (>= 0.90.0, < 2.0)
132
+ rubocop-ast (>= 0.4.0)
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)
139
+ ruby_parser (3.15.0)
129
140
  sexp_processor (~> 4.9)
130
- sexp_processor (4.12.1)
131
- sqlite3 (1.4.1)
132
- thor (0.20.3)
133
- thread_safe (0.3.6)
134
- tzinfo (1.2.5)
135
- thread_safe (~> 0.1)
136
- unicode-display_width (1.6.0)
137
- zeitwerk (2.1.9)
141
+ sexp_processor (4.15.1)
142
+ sqlite3 (1.4.2)
143
+ thor (1.0.1)
144
+ tzinfo (2.0.4)
145
+ concurrent-ruby (~> 1.0)
146
+ unicode-display_width (1.7.0)
147
+ zeitwerk (2.4.2)
138
148
 
139
149
  PLATFORMS
140
150
  ruby
@@ -151,8 +161,9 @@ DEPENDENCIES
151
161
  rspec-rails
152
162
  rubocop
153
163
  rubocop-performance
164
+ rubocop-rake
154
165
  rubocop-rspec
155
166
  sqlite3
156
167
 
157
168
  BUNDLED WITH
158
- 2.0.1
169
+ 2.1.4
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
 
@@ -7,7 +7,7 @@ class Lite::Report::Array < Lite::Report::Base
7
7
  end
8
8
 
9
9
  def import
10
- CSV.foreach(@data, @csv_options)
10
+ CSV.foreach(@data, **@csv_options)
11
11
  .with_object([]) do |row, array|
12
12
  row = convert_to_array!(row)
13
13
  array << process_import_row!(row)
@@ -10,7 +10,7 @@ module Lite
10
10
  def initialize
11
11
  @csv_options = {}
12
12
  @data_options = {}
13
- @import_adapter = {}
13
+ @import_options = {}
14
14
  end
15
15
 
16
16
  end
@@ -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
@@ -8,7 +8,7 @@ class Lite::Report::Hash < Lite::Report::Base
8
8
  end
9
9
 
10
10
  def import
11
- CSV.foreach(@data, @csv_options)
11
+ CSV.foreach(@data, **@csv_options)
12
12
  .with_object([]) do |row, array|
13
13
  next if header_row?(row)
14
14
 
@@ -10,7 +10,14 @@ module Lite
10
10
  def encode(cell)
11
11
  return cell unless cell.is_a?(String)
12
12
 
13
- cell.tr('"', '').encode!(*@data_options[:encode])
13
+ cell = cell.tr('"', '')
14
+ return cell if @data_options[:encode].empty?
15
+
16
+ cell.encode!(
17
+ @data_options[:encode][0],
18
+ @data_options[:encode][1],
19
+ **@data_options[:encode][2]
20
+ )
14
21
  end
15
22
 
16
23
  def encode?(delete: false)
@@ -10,7 +10,7 @@ module Lite
10
10
  def class_columns(data)
11
11
  return data.klass.column_names if ransack_class?(data)
12
12
 
13
- data.column_names
13
+ data.try(:column_names) || data.class.column_names
14
14
  end
15
15
 
16
16
  def klass
@@ -8,7 +8,7 @@ module Lite
8
8
  private
9
9
 
10
10
  def generate_export!
11
- CSV.generate(@csv_options) do |csv|
11
+ CSV.generate(**@csv_options) do |csv|
12
12
  @data.each do |row|
13
13
  csv << process_export_row!(row)
14
14
  end
@@ -33,7 +33,7 @@ module Lite
33
33
 
34
34
  @data.each do |row|
35
35
  row = process_export_row!(row)
36
- csv << CSV.generate_line(row, @csv_options)
36
+ csv << CSV.generate_line(row, **@csv_options)
37
37
  end
38
38
  end
39
39
  end
@@ -18,7 +18,7 @@ class Lite::Report::Record < Lite::Report::Base
18
18
  @data = Lite::Report::Hash.import(@data, csv_options: @csv_options, data_options: @data_options)
19
19
  .each { |row| row.delete(:id) || row.delete('id') }
20
20
 
21
- klass.import(@data, @import_options)
21
+ klass.import(@data, **@import_options)
22
22
  end
23
23
 
24
24
  private
@@ -43,6 +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] if !@data.respond_to?(:each) || !@data.is_a?(Array)
46
47
  end
47
48
 
48
49
  def generate_export!
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Report
5
5
 
6
- VERSION ||= '1.0.2'
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.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-24 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
@@ -220,7 +234,7 @@ dependencies:
220
234
  - - ">="
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
- description:
237
+ description:
224
238
  email:
225
239
  - j.gomez@drexed.com
226
240
  executables: []
@@ -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
@@ -264,7 +279,7 @@ homepage: http://drexed.github.io/lite-report
264
279
  licenses:
265
280
  - MIT
266
281
  metadata: {}
267
- post_install_message:
282
+ post_install_message:
268
283
  rdoc_options: []
269
284
  require_paths:
270
285
  - lib
@@ -279,8 +294,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
294
  - !ruby/object:Gem::Version
280
295
  version: '0'
281
296
  requirements: []
282
- rubygems_version: 3.0.4
283
- signing_key:
297
+ rubygems_version: 3.2.4
298
+ signing_key:
284
299
  specification_version: 4
285
300
  summary: Import and export Ruby and Rails objects to flat files and vice versa
286
301
  test_files: []