lite-report 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +11 -0
- data/.rspec +4 -0
- data/.rubocop.yml +28 -0
- data/.travis.yml +24 -0
- data/CHANGELOG.md +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +155 -0
- data/LICENSE.txt +21 -0
- data/README.md +202 -0
- data/Rakefile +8 -0
- data/_config.yml +1 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/lite/report/install_generator.rb +17 -0
- data/lib/generators/lite/report/templates/install.rb +7 -0
- data/lib/lite/report.rb +14 -0
- data/lib/lite/report/array.rb +17 -0
- data/lib/lite/report/base.rb +56 -0
- data/lib/lite/report/configuration.rb +31 -0
- data/lib/lite/report/hash.rb +28 -0
- data/lib/lite/report/helpers/converters.rb +28 -0
- data/lib/lite/report/helpers/encoders.rb +42 -0
- data/lib/lite/report/helpers/filters.rb +56 -0
- data/lib/lite/report/helpers/headers.rb +37 -0
- data/lib/lite/report/helpers/processors.rb +26 -0
- data/lib/lite/report/helpers/records.rb +29 -0
- data/lib/lite/report/helpers/transporters.rb +44 -0
- data/lib/lite/report/record.rb +58 -0
- data/lib/lite/report/version.rb +9 -0
- data/lite-report.gemspec +56 -0
- metadata +286 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lite
|
4
|
+
module Report
|
5
|
+
module Helpers
|
6
|
+
module Transporters
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def generate_export!
|
11
|
+
CSV.generate(@csv_options) do |csv|
|
12
|
+
@data.each do |row|
|
13
|
+
csv << process_export_row!(row)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_or_stream_export!
|
19
|
+
return stream_export! if stream?(delete: true)
|
20
|
+
|
21
|
+
generate_export!
|
22
|
+
end
|
23
|
+
|
24
|
+
def stream?(delete: false)
|
25
|
+
return @csv_options.delete(:stream) if delete
|
26
|
+
|
27
|
+
@csv_options[:stream]
|
28
|
+
end
|
29
|
+
|
30
|
+
def stream_export!
|
31
|
+
Enumerator.new do |csv|
|
32
|
+
csv << CSV.generate_line(headers?(delete: true)) if write_headers?(delete: true)
|
33
|
+
|
34
|
+
@data.each do |row|
|
35
|
+
row = process_export_row!(row)
|
36
|
+
csv << CSV.generate_line(row, @csv_options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
require 'activerecord-import'
|
5
|
+
require 'deep_pluck'
|
6
|
+
|
7
|
+
class Lite::Report::Record < Lite::Report::Base
|
8
|
+
|
9
|
+
def export
|
10
|
+
assign_headers_to_csv_options!
|
11
|
+
generate_or_stream_export!
|
12
|
+
end
|
13
|
+
|
14
|
+
def import
|
15
|
+
assert_klass_data_option!
|
16
|
+
assign_import_csv_options!
|
17
|
+
|
18
|
+
@data = Lite::Report::Hash.import(@data, csv_options: @csv_options, data_options: @data_options)
|
19
|
+
.each { |row| row.delete(:id) || row.delete('id') }
|
20
|
+
|
21
|
+
klass.import(@data, @import_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def assert_klass_data_option!
|
27
|
+
return if klass
|
28
|
+
|
29
|
+
raise ArgumentError, '":klass" data_option is required'
|
30
|
+
end
|
31
|
+
|
32
|
+
def assign_headers_to_csv_options!
|
33
|
+
return unless write_headers?
|
34
|
+
|
35
|
+
@csv_options[:headers] ||= class_columns(@data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assign_import_csv_options!
|
39
|
+
@csv_options[:headers] ||= class_columns(klass)
|
40
|
+
end
|
41
|
+
|
42
|
+
def assign_export_data!
|
43
|
+
columns = class_columns(@data)
|
44
|
+
@data = @data.result if ransack_class?(@data)
|
45
|
+
@data = @data.deep_pluck(*columns)
|
46
|
+
end
|
47
|
+
|
48
|
+
def generate_export!
|
49
|
+
assign_export_data!
|
50
|
+
super
|
51
|
+
end
|
52
|
+
|
53
|
+
def stream_export!
|
54
|
+
assign_export_data!
|
55
|
+
super
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lite-report.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'lite/report/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'lite-report'
|
9
|
+
spec.version = Lite::Report::VERSION
|
10
|
+
spec.authors = ['Juan Gomez']
|
11
|
+
spec.email = %w[j.gomez@drexed.com]
|
12
|
+
|
13
|
+
spec.summary = 'Import and export Ruby and Rails objects to flat files and vice versa'
|
14
|
+
spec.homepage = 'http://drexed.github.io/lite-report'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata.merge(
|
21
|
+
'allowed_push_host' => 'https://rubygems.org',
|
22
|
+
'changelog_uri' => 'https://github.com/drexed/lite-report/blob/master/CHANGELOG.md',
|
23
|
+
'homepage_uri' => spec.homepage,
|
24
|
+
'source_code_uri' => 'https://github.com/drexed/lite-report'
|
25
|
+
)
|
26
|
+
else
|
27
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
28
|
+
'public gem pushes.'
|
29
|
+
end
|
30
|
+
|
31
|
+
# Specify which files should be added to the gem when it is released.
|
32
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
33
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
34
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
35
|
+
end
|
36
|
+
spec.bindir = 'exe'
|
37
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
|
+
spec.require_paths = %w[lib]
|
39
|
+
|
40
|
+
spec.add_runtime_dependency 'activerecord'
|
41
|
+
spec.add_runtime_dependency 'activerecord-import'
|
42
|
+
spec.add_runtime_dependency 'deep_pluck'
|
43
|
+
|
44
|
+
spec.add_development_dependency 'bundler'
|
45
|
+
spec.add_development_dependency 'database_cleaner'
|
46
|
+
spec.add_development_dependency 'fasterer'
|
47
|
+
spec.add_development_dependency 'generator_spec'
|
48
|
+
spec.add_development_dependency 'rake'
|
49
|
+
spec.add_development_dependency 'ransack'
|
50
|
+
spec.add_development_dependency 'rspec'
|
51
|
+
spec.add_development_dependency 'rspec-rails'
|
52
|
+
spec.add_development_dependency 'rubocop'
|
53
|
+
spec.add_development_dependency 'rubocop-performance'
|
54
|
+
spec.add_development_dependency 'rubocop-rspec'
|
55
|
+
spec.add_development_dependency 'sqlite3'
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lite-report
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juan Gomez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: database_cleaner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fasterer
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: generator_spec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ransack
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec-rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop-performance
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-rspec
|
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'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: sqlite3
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
description:
|
224
|
+
email:
|
225
|
+
- j.gomez@drexed.com
|
226
|
+
executables: []
|
227
|
+
extensions: []
|
228
|
+
extra_rdoc_files: []
|
229
|
+
files:
|
230
|
+
- ".DS_Store"
|
231
|
+
- ".fasterer.yml"
|
232
|
+
- ".gitignore"
|
233
|
+
- ".rspec"
|
234
|
+
- ".rubocop.yml"
|
235
|
+
- ".travis.yml"
|
236
|
+
- CHANGELOG.md
|
237
|
+
- CODE_OF_CONDUCT.md
|
238
|
+
- Gemfile
|
239
|
+
- Gemfile.lock
|
240
|
+
- LICENSE.txt
|
241
|
+
- README.md
|
242
|
+
- Rakefile
|
243
|
+
- _config.yml
|
244
|
+
- bin/console
|
245
|
+
- bin/setup
|
246
|
+
- lib/generators/lite/report/install_generator.rb
|
247
|
+
- lib/generators/lite/report/templates/install.rb
|
248
|
+
- lib/lite/report.rb
|
249
|
+
- lib/lite/report/array.rb
|
250
|
+
- lib/lite/report/base.rb
|
251
|
+
- lib/lite/report/configuration.rb
|
252
|
+
- lib/lite/report/hash.rb
|
253
|
+
- lib/lite/report/helpers/converters.rb
|
254
|
+
- lib/lite/report/helpers/encoders.rb
|
255
|
+
- lib/lite/report/helpers/filters.rb
|
256
|
+
- lib/lite/report/helpers/headers.rb
|
257
|
+
- lib/lite/report/helpers/processors.rb
|
258
|
+
- lib/lite/report/helpers/records.rb
|
259
|
+
- lib/lite/report/helpers/transporters.rb
|
260
|
+
- lib/lite/report/record.rb
|
261
|
+
- lib/lite/report/version.rb
|
262
|
+
- lite-report.gemspec
|
263
|
+
homepage: http://drexed.github.io/lite-report
|
264
|
+
licenses:
|
265
|
+
- MIT
|
266
|
+
metadata: {}
|
267
|
+
post_install_message:
|
268
|
+
rdoc_options: []
|
269
|
+
require_paths:
|
270
|
+
- lib
|
271
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
272
|
+
requirements:
|
273
|
+
- - ">="
|
274
|
+
- !ruby/object:Gem::Version
|
275
|
+
version: '0'
|
276
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
277
|
+
requirements:
|
278
|
+
- - ">="
|
279
|
+
- !ruby/object:Gem::Version
|
280
|
+
version: '0'
|
281
|
+
requirements: []
|
282
|
+
rubygems_version: 3.0.4
|
283
|
+
signing_key:
|
284
|
+
specification_version: 4
|
285
|
+
summary: Import and export Ruby and Rails objects to flat files and vice versa
|
286
|
+
test_files: []
|