lite-report 1.1.1 → 1.2.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: 9559d49c8162d5c74d507ad986917f959add7da9a95d3566b36a3a3668194db5
4
- data.tar.gz: acaf0fec27642dbb3b1d6244ece60467065adc76cdc8709eaa48766bb27198dc
3
+ metadata.gz: e5306a141edec1f32743651c3fe81fc7d9f99a4f091ae21b2cee30de8e428b02
4
+ data.tar.gz: bef4ad772798d30c09c27ad0807201b0701062372b52ca7adfc3094715a6c636
5
5
  SHA512:
6
- metadata.gz: a8f6269d6985c6ade54c2c3a2efd73751053cb653341fdb96edeb9e2fea935b59afaebbc62eed75a30b13157bc4b16516f8a537f398d2e53b788cb8f9782ad6a
7
- data.tar.gz: 6bce2655d3e3aec419000de951a65cd369136ee63d10933c5744e326ac49de884a2cd91cf8dce588cc220706c8f25118351a3801713e24b6611af46aec02bffd
6
+ metadata.gz: effd567e92022ea1c3487694d41d692cb46fb5f01678676627d3c9deca79739c3fd61ce0994157067ad4ba0430f459a65b1fd5c61e541a33511056ebe7eb6355
7
+ data.tar.gz: 1d165fe27b4495ab9a594f7ff4c7f91f23c40d92309044c53ca21815134d6349ef6f4dd4fd538d1359db9a318c68989c31424c38b94738bd39b44255cccf5f07
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.20.0] - 2021-07-18
10
+ ### Removed
11
+ - Removed `activerecord-import` dependency
12
+ - Removed `deep_pluck` dependency
13
+
9
14
  ## [1.1.1] - 2021-05-07
10
15
  ### Changed
11
16
  - Linter fixes
data/Gemfile.lock CHANGED
@@ -1,35 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-report (1.1.1)
4
+ lite-report (1.2.0)
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.3.2)
13
- actionview (= 6.1.3.2)
14
- activesupport (= 6.1.3.2)
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.3.2)
20
- activesupport (= 6.1.3.2)
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.3.2)
26
- activesupport (= 6.1.3.2)
27
- activerecord (6.1.3.2)
28
- activemodel (= 6.1.3.2)
29
- activesupport (= 6.1.3.2)
30
- activerecord-import (1.0.8)
31
- activerecord (>= 3.2)
32
- activesupport (6.1.3.2)
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)
@@ -38,18 +34,14 @@ GEM
38
34
  ast (2.4.2)
39
35
  builder (3.2.4)
40
36
  colorize (0.8.1)
41
- concurrent-ruby (1.1.8)
37
+ concurrent-ruby (1.1.9)
42
38
  crass (1.0.6)
43
39
  database_cleaner (2.0.1)
44
40
  database_cleaner-active_record (~> 2.0.0)
45
- database_cleaner-active_record (2.0.0)
41
+ database_cleaner-active_record (2.0.1)
46
42
  activerecord (>= 5.a)
47
43
  database_cleaner-core (~> 2.0.0)
48
44
  database_cleaner-core (2.0.1)
49
- deep_pluck (1.1.7)
50
- activerecord (>= 3)
51
- pluck_all (>= 1.2.3)
52
- rails_compatibility (>= 0.0.4)
53
45
  diff-lcs (1.4.4)
54
46
  erubi (1.10.0)
55
47
  fasterer (0.9.0)
@@ -60,21 +52,18 @@ GEM
60
52
  railties (>= 3.0.0)
61
53
  i18n (1.8.10)
62
54
  concurrent-ruby (~> 1.0)
63
- loofah (2.9.1)
55
+ loofah (2.10.0)
64
56
  crass (~> 1.0.2)
65
57
  nokogiri (>= 1.5.9)
66
58
  method_source (1.0.0)
67
- mini_portile2 (2.5.1)
59
+ mini_portile2 (2.5.3)
68
60
  minitest (5.14.4)
69
- nokogiri (1.11.3)
61
+ nokogiri (1.11.7)
70
62
  mini_portile2 (~> 2.5.0)
71
63
  racc (~> 1.4)
72
64
  parallel (1.20.1)
73
- parser (3.0.1.1)
65
+ parser (3.0.2.0)
74
66
  ast (~> 2.4.1)
75
- pluck_all (2.2.1)
76
- activesupport (>= 3.0.0)
77
- rails_compatibility (>= 0.0.2)
78
67
  racc (1.5.2)
79
68
  rack (2.2.3)
80
69
  rack-test (1.1.0)
@@ -84,16 +73,14 @@ GEM
84
73
  nokogiri (>= 1.6)
85
74
  rails-html-sanitizer (1.3.0)
86
75
  loofah (~> 2.3)
87
- rails_compatibility (0.0.5)
88
- activerecord (>= 3)
89
- railties (6.1.3.2)
90
- actionpack (= 6.1.3.2)
91
- activesupport (= 6.1.3.2)
76
+ railties (6.1.4)
77
+ actionpack (= 6.1.4)
78
+ activesupport (= 6.1.4)
92
79
  method_source
93
- rake (>= 0.8.7)
80
+ rake (>= 0.13)
94
81
  thor (~> 1.0)
95
82
  rainbow (3.0.0)
96
- rake (13.0.3)
83
+ rake (13.0.6)
97
84
  ransack (2.4.2)
98
85
  activerecord (>= 5.2.4)
99
86
  activesupport (>= 5.2.4)
@@ -121,29 +108,29 @@ GEM
121
108
  rspec-mocks (~> 3.10)
122
109
  rspec-support (~> 3.10)
123
110
  rspec-support (3.10.2)
124
- rubocop (1.14.0)
111
+ rubocop (1.18.3)
125
112
  parallel (~> 1.10)
126
113
  parser (>= 3.0.0.0)
127
114
  rainbow (>= 2.2.2, < 4.0)
128
115
  regexp_parser (>= 1.8, < 3.0)
129
116
  rexml
130
- rubocop-ast (>= 1.5.0, < 2.0)
117
+ rubocop-ast (>= 1.7.0, < 2.0)
131
118
  ruby-progressbar (~> 1.7)
132
119
  unicode-display_width (>= 1.4.0, < 3.0)
133
- rubocop-ast (1.5.0)
120
+ rubocop-ast (1.8.0)
134
121
  parser (>= 3.0.1.1)
135
- rubocop-performance (1.11.3)
122
+ rubocop-performance (1.11.4)
136
123
  rubocop (>= 1.7.0, < 2.0)
137
124
  rubocop-ast (>= 0.4.0)
138
- rubocop-rake (0.5.1)
139
- rubocop
140
- rubocop-rspec (2.3.0)
125
+ rubocop-rake (0.6.0)
126
+ rubocop (~> 1.0)
127
+ rubocop-rspec (2.4.0)
141
128
  rubocop (~> 1.0)
142
129
  rubocop-ast (>= 1.1.0)
143
130
  ruby-progressbar (1.11.0)
144
- ruby_parser (3.15.1)
145
- sexp_processor (~> 4.9)
146
- sexp_processor (4.15.2)
131
+ ruby_parser (3.16.0)
132
+ sexp_processor (~> 4.15, >= 4.15.1)
133
+ sexp_processor (4.15.3)
147
134
  sqlite3 (1.4.2)
148
135
  thor (1.1.0)
149
136
  tzinfo (2.0.4)
@@ -171,4 +158,4 @@ DEPENDENCIES
171
158
  sqlite3
172
159
 
173
160
  BUNDLED WITH
174
- 2.2.17
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,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.1'
6
+ VERSION = '1.2.0'
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.1
4
+ version: 1.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: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-07-19 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.17
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