lite-report 1.1.0 → 1.3.1

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: 6c47012894f22e7cb6329fd29cd11d674436a26e0721042f92f8686827854ff2
4
- data.tar.gz: 5bc35bc9c3f4604121aeb9a9fe519a582f4da4ed5aa7aed0afbd64e8fba5591d
3
+ metadata.gz: 5eef18beb2798dff3053f07868581c626de955a02cb9ffa9734336ba8fbe2e3c
4
+ data.tar.gz: 4e02507048f43678d3cea53b0fda428f5801b4405381d97275e4713ce93859c5
5
5
  SHA512:
6
- metadata.gz: fb991fc839a2287a65de08bc70c3e44cc59a003618a2ef4db6eb2f05ece1e028c12ab71c86f6242c8423a723e6dd826414d2eb123fcd8af6b853146672aff5a9
7
- data.tar.gz: b957984a667255674fd66e2122e2c813b515cbe04daff7c5e0227eb74c44c3c0425024945012a857901b92e3131277c7774e812a04f8e59802afb4d52c25672a
6
+ metadata.gz: 416502eb1aa8c0fe150cb0346cd2d6a2c7c6ec42d6c9fa51f533a4b16b23e83d4fd94e31ad5c2ca663706ffd70c72921a26d764b7dc350fe1b66aa2e87e7b661
7
+ data.tar.gz: bb6900054c612fae30583cdbd9664643fa3a558607239fa94df1385a54fd9a6f47f32d96e2c390b1d4223ffd83aca2ac7ce80d7d47cb796246e52f3cb2513e10
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ require:
3
3
  - rubocop-rake
4
4
  - rubocop-rspec
5
5
  AllCops:
6
- TargetRubyVersion: 2.7
6
+ TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
  DisplayCopNames: true
9
9
  DisplayStyleGuide: true
@@ -32,6 +32,8 @@ Metrics/BlockLength:
32
32
  - '*.gemspec'
33
33
  RSpec/ExampleLength:
34
34
  Enabled: false
35
+ Style/ArgumentsForwarding:
36
+ Enabled: false
35
37
  Style/ClassAndModuleChildren:
36
38
  Enabled: false
37
39
  Style/Documentation:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.3.1] - 2021-07-21
10
+ ### Changed
11
+ - Improved Railtie support
12
+
13
+ ## [1.3.0] - 2021-07-19
14
+ ### Added
15
+ - Added Ruby 3.0 support
16
+
17
+ ## [1.2.0] - 2021-07-18
18
+ ### Removed
19
+ - Removed `activerecord-import` dependency
20
+ - Removed `deep_pluck` dependency
21
+
22
+ ## [1.1.1] - 2021-05-07
23
+ ### Changed
24
+ - Linter fixes
25
+
9
26
  ## [1.1.0] - 2021-01-06
10
27
  ### Added
11
28
  - Added Exporter helper class
data/Gemfile.lock CHANGED
@@ -1,75 +1,69 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-report (1.1.0)
4
+ lite-report (1.3.1)
5
5
  activerecord
6
- activerecord-import
7
- deep_pluck
8
6
 
9
7
  GEM
10
8
  remote: https://rubygems.org/
11
9
  specs:
12
- actionpack (6.1.0)
13
- actionview (= 6.1.0)
14
- activesupport (= 6.1.0)
10
+ actionpack (6.1.4)
11
+ actionview (= 6.1.4)
12
+ activesupport (= 6.1.4)
15
13
  rack (~> 2.0, >= 2.0.9)
16
14
  rack-test (>= 0.6.3)
17
15
  rails-dom-testing (~> 2.0)
18
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
19
- actionview (6.1.0)
20
- activesupport (= 6.1.0)
17
+ actionview (6.1.4)
18
+ activesupport (= 6.1.4)
21
19
  builder (~> 3.1)
22
20
  erubi (~> 1.4)
23
21
  rails-dom-testing (~> 2.0)
24
22
  rails-html-sanitizer (~> 1.1, >= 1.2.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
- activerecord (>= 3.2)
32
- activesupport (6.1.0)
23
+ activemodel (6.1.4)
24
+ activesupport (= 6.1.4)
25
+ activerecord (6.1.4)
26
+ activemodel (= 6.1.4)
27
+ activesupport (= 6.1.4)
28
+ activesupport (6.1.4)
33
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
34
30
  i18n (>= 1.6, < 2)
35
31
  minitest (>= 5.1)
36
32
  tzinfo (~> 2.0)
37
33
  zeitwerk (~> 2.3)
38
- ast (2.4.1)
34
+ ast (2.4.2)
39
35
  builder (3.2.4)
40
36
  colorize (0.8.1)
41
- concurrent-ruby (1.1.7)
37
+ concurrent-ruby (1.1.9)
42
38
  crass (1.0.6)
43
- database_cleaner (1.8.5)
44
- deep_pluck (1.1.4)
45
- activerecord (>= 3)
46
- pluck_all (>= 1.2.3)
47
- rails_compatibility (>= 0.0.1)
39
+ database_cleaner (2.0.1)
40
+ database_cleaner-active_record (~> 2.0.0)
41
+ database_cleaner-active_record (2.0.1)
42
+ activerecord (>= 5.a)
43
+ database_cleaner-core (~> 2.0.0)
44
+ database_cleaner-core (2.0.1)
48
45
  diff-lcs (1.4.4)
49
46
  erubi (1.10.0)
50
- fasterer (0.8.3)
47
+ fasterer (0.9.0)
51
48
  colorize (~> 0.7)
52
49
  ruby_parser (>= 3.14.1)
53
50
  generator_spec (0.9.4)
54
51
  activesupport (>= 3.0.0)
55
52
  railties (>= 3.0.0)
56
- i18n (1.8.7)
53
+ i18n (1.8.10)
57
54
  concurrent-ruby (~> 1.0)
58
- loofah (2.8.0)
55
+ loofah (2.10.0)
59
56
  crass (~> 1.0.2)
60
57
  nokogiri (>= 1.5.9)
61
58
  method_source (1.0.0)
62
- mini_portile2 (2.5.0)
63
- minitest (5.14.3)
64
- nokogiri (1.11.1)
59
+ mini_portile2 (2.5.3)
60
+ minitest (5.14.4)
61
+ nokogiri (1.11.7)
65
62
  mini_portile2 (~> 2.5.0)
66
63
  racc (~> 1.4)
67
64
  parallel (1.20.1)
68
- parser (3.0.0.0)
65
+ parser (3.0.2.0)
69
66
  ast (~> 2.4.1)
70
- pluck_all (2.2.1)
71
- activesupport (>= 3.0.0)
72
- rails_compatibility (>= 0.0.2)
73
67
  racc (1.5.2)
74
68
  rack (2.2.3)
75
69
  rack-test (1.1.0)
@@ -79,22 +73,20 @@ GEM
79
73
  nokogiri (>= 1.6)
80
74
  rails-html-sanitizer (1.3.0)
81
75
  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)
76
+ railties (6.1.4)
77
+ actionpack (= 6.1.4)
78
+ activesupport (= 6.1.4)
87
79
  method_source
88
- rake (>= 0.8.7)
80
+ rake (>= 0.13)
89
81
  thor (~> 1.0)
90
82
  rainbow (3.0.0)
91
- rake (13.0.3)
92
- ransack (2.4.1)
83
+ rake (13.0.6)
84
+ ransack (2.4.2)
93
85
  activerecord (>= 5.2.4)
94
86
  activesupport (>= 5.2.4)
95
87
  i18n
96
- regexp_parser (2.0.3)
97
- rexml (3.2.4)
88
+ regexp_parser (2.1.1)
89
+ rexml (3.2.5)
98
90
  rspec (3.10.0)
99
91
  rspec-core (~> 3.10.0)
100
92
  rspec-expectations (~> 3.10.0)
@@ -104,46 +96,46 @@ GEM
104
96
  rspec-expectations (3.10.1)
105
97
  diff-lcs (>= 1.2.0, < 2.0)
106
98
  rspec-support (~> 3.10.0)
107
- rspec-mocks (3.10.1)
99
+ rspec-mocks (3.10.2)
108
100
  diff-lcs (>= 1.2.0, < 2.0)
109
101
  rspec-support (~> 3.10.0)
110
- rspec-rails (4.0.2)
111
- actionpack (>= 4.2)
112
- activesupport (>= 4.2)
113
- railties (>= 4.2)
102
+ rspec-rails (5.0.1)
103
+ actionpack (>= 5.2)
104
+ activesupport (>= 5.2)
105
+ railties (>= 5.2)
114
106
  rspec-core (~> 3.10)
115
107
  rspec-expectations (~> 3.10)
116
108
  rspec-mocks (~> 3.10)
117
109
  rspec-support (~> 3.10)
118
- rspec-support (3.10.1)
119
- rubocop (1.7.0)
110
+ rspec-support (3.10.2)
111
+ rubocop (1.18.3)
120
112
  parallel (~> 1.10)
121
- parser (>= 2.7.1.5)
113
+ parser (>= 3.0.0.0)
122
114
  rainbow (>= 2.2.2, < 4.0)
123
115
  regexp_parser (>= 1.8, < 3.0)
124
116
  rexml
125
- rubocop-ast (>= 1.2.0, < 2.0)
117
+ rubocop-ast (>= 1.7.0, < 2.0)
126
118
  ruby-progressbar (~> 1.7)
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)
119
+ unicode-display_width (>= 1.4.0, < 3.0)
120
+ rubocop-ast (1.8.0)
121
+ parser (>= 3.0.1.1)
122
+ rubocop-performance (1.11.4)
123
+ rubocop (>= 1.7.0, < 2.0)
132
124
  rubocop-ast (>= 0.4.0)
133
- rubocop-rake (0.5.1)
134
- rubocop
135
- rubocop-rspec (2.1.0)
125
+ rubocop-rake (0.6.0)
126
+ rubocop (~> 1.0)
127
+ rubocop-rspec (2.4.0)
136
128
  rubocop (~> 1.0)
137
129
  rubocop-ast (>= 1.1.0)
138
130
  ruby-progressbar (1.11.0)
139
- ruby_parser (3.15.0)
140
- sexp_processor (~> 4.9)
141
- sexp_processor (4.15.1)
131
+ ruby_parser (3.16.0)
132
+ sexp_processor (~> 4.15, >= 4.15.1)
133
+ sexp_processor (4.15.3)
142
134
  sqlite3 (1.4.2)
143
- thor (1.0.1)
135
+ thor (1.1.0)
144
136
  tzinfo (2.0.4)
145
137
  concurrent-ruby (~> 1.0)
146
- unicode-display_width (1.7.0)
138
+ unicode-display_width (2.0.0)
147
139
  zeitwerk (2.4.2)
148
140
 
149
141
  PLATFORMS
@@ -166,4 +158,4 @@ DEPENDENCIES
166
158
  sqlite3
167
159
 
168
160
  BUNDLED WITH
169
- 2.1.4
161
+ 2.2.24
data/README.md CHANGED
@@ -135,12 +135,15 @@ Lite::Report::Record.export(
135
135
  }
136
136
  )
137
137
 
138
- # Convert CSV file to an array of records
138
+ # Convert CSV file to an array of records (import options are from Rails `insert_all`)
139
139
  Lite::Report::Record.import(
140
140
  'path/to/file.csv',
141
141
  data_options: {
142
142
  klass: User,
143
143
  except: [:age, :sex]
144
+ },
145
+ import_options: {
146
+ unique_by: %w[Name Age]
144
147
  }
145
148
  )
146
149
  ```
@@ -162,6 +165,11 @@ class LimitedExporter < Lite::Report::Exporter
162
165
  'Speed' => record.speed.ceil,
163
166
  'Date' => record.to_s(:short)
164
167
  }
168
+
169
+ # - or -
170
+
171
+ serializer = RecordSerializer.new(record)
172
+ serializer.serializable_hash
165
173
  end
166
174
 
167
175
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rails/generators'
4
-
5
3
  module Lite
6
4
  module Report
7
5
  class InstallGenerator < Rails::Generators::Base
data/lib/lite/report.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'csv'
3
+ require 'csv' unless defined?(CSV)
4
+
5
+ require 'generators/lite/report/install_generator' if defined?(Rails::Generators)
6
+
4
7
  require 'lite/report/version'
5
8
 
6
9
  %w[converters encoders filters headers processors records transporters].each do |file_name|
@@ -10,5 +13,3 @@ end
10
13
  %w[configuration base array hash record exporter].each do |file_name|
11
14
  require "lite/report/#{file_name}"
12
15
  end
13
-
14
- require 'generators/lite/report/install_generator'
@@ -16,7 +16,7 @@ module Lite
16
16
 
17
17
  def convert_to_hash!(row)
18
18
  case row.class.name
19
- when 'Array' then ::Hash[(0..(row.size - 1)).zip(row)]
19
+ when 'Array' then (0..(row.size - 1)).zip(row).to_h
20
20
  when 'CSV::Row' then row.to_hash
21
21
  else row
22
22
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_record'
4
- require 'activerecord-import'
5
- require 'deep_pluck'
6
4
 
7
5
  class Lite::Report::Record < Lite::Report::Base
8
6
 
@@ -16,9 +14,13 @@ class Lite::Report::Record < Lite::Report::Base
16
14
  assign_import_csv_options!
17
15
 
18
16
  @data = Lite::Report::Hash.import(@data, csv_options: @csv_options, data_options: @data_options)
19
- .each { |row| row.delete(:id) || row.delete('id') }
17
+ .each do |row|
18
+ row.delete(:id) || row.delete('id')
19
+ (row['created_at'] ||= timestamp) if created_at_timestamp?
20
+ (row['updated_at'] ||= timestamp) if updated_at_timestamp?
21
+ end
20
22
 
21
- klass.import(@data, **@import_options)
23
+ klass.insert_all(@data, **@import_options)
22
24
  end
23
25
 
24
26
  private
@@ -41,9 +43,15 @@ class Lite::Report::Record < Lite::Report::Base
41
43
 
42
44
  def assign_export_data!
43
45
  columns = class_columns(@data)
44
- @data = @data.result if ransack_class?(@data)
45
- @data = @data.deep_pluck(*columns)
46
- @data = [@data] if !@data.respond_to?(:each) || !@data.is_a?(Array)
46
+ @data = if ransack_class?(@data)
47
+ @data.result
48
+ elsif @data.try(:persisted?)
49
+ Array(@data)
50
+ else
51
+ @data
52
+ end
53
+
54
+ @data = @data.pluck(*columns).map { |values| columns.zip(values).to_h }
47
55
  end
48
56
 
49
57
  def generate_export!
@@ -56,4 +64,20 @@ class Lite::Report::Record < Lite::Report::Base
56
64
  super
57
65
  end
58
66
 
67
+ def timestamp
68
+ @timestamp ||= Time.try(:current) || Time.now
69
+ end
70
+
71
+ def created_at_timestamp?
72
+ return @created_at_timestamp if defined?(@created_at_timestamp)
73
+
74
+ @created_at_timestamp = klass.new.respond_to?(:created_at)
75
+ end
76
+
77
+ def updated_at_timestamp?
78
+ return @updated_at_timestamp if defined?(@updated_at_timestamp)
79
+
80
+ @updated_at_timestamp = klass.new.respond_to?(:updated_at)
81
+ end
82
+
59
83
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Report
5
5
 
6
- VERSION ||= '1.1.0'
6
+ VERSION = '1.3.1'
7
7
 
8
8
  end
9
9
  end
data/lite-report.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  )
26
26
  else
27
27
  raise 'RubyGems 2.0 or newer is required to protect against ' \
28
- 'public gem pushes.'
28
+ 'public gem pushes.'
29
29
  end
30
30
 
31
31
  # Specify which files should be added to the gem when it is released.
@@ -38,8 +38,6 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = %w[lib]
39
39
 
40
40
  spec.add_runtime_dependency 'activerecord'
41
- spec.add_runtime_dependency 'activerecord-import'
42
- spec.add_runtime_dependency 'deep_pluck'
43
41
 
44
42
  spec.add_development_dependency 'bundler'
45
43
  spec.add_development_dependency 'database_cleaner'
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.1.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-06 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,34 +24,6 @@ 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'
41
- - !ruby/object:Gem::Dependency
42
- name: deep_pluck
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: bundler
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -294,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
266
  - !ruby/object:Gem::Version
295
267
  version: '0'
296
268
  requirements: []
297
- rubygems_version: 3.2.4
269
+ rubygems_version: 3.2.24
298
270
  signing_key:
299
271
  specification_version: 4
300
272
  summary: Import and export Ruby and Rails objects to flat files and vice versa