lite-report 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '01200390e3a06669140612cf102393844a3121b27b71905e3df0adcfa275a299'
4
+ data.tar.gz: 808ce98ff9635dcd92d59b09eeec9a397b556f2f4d064e5e76c67ff4e99cc282
5
+ SHA512:
6
+ metadata.gz: 53eb09f4960b0aa89e5cc6391cc86bdb674b115a171414bb88ee45992e4724b0a9c467c2e491beb744177c41f7553bc113ba51cf339a4e2159ea0b9db410071e
7
+ data.tar.gz: 99ccc7f5f644d53486843984f3211589ce7bd07a3f738dadbfad1de83020d44f52b971ec50cc1857855b8003be4b81510c16d1f5e7f242ea846e08b120035e1b
Binary file
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ block_vs_symbol_to_proc: true
3
+ each_with_index_vs_while: false
4
+ fetch_with_argument_vs_block: true
5
+ for_loop_vs_each: true
6
+ getter_vs_attr_reader: true
7
+ gsub_vs_tr: true
8
+ hash_merge_bang_vs_hash_brackets: true
9
+ keys_each_vs_each_key: true
10
+ map_flatten_vs_flat_map: true
11
+ module_eval: true
12
+ proc_call_vs_yield: true
13
+ rescue_vs_respond_to: true
14
+ reverse_each_vs_reverse_each: true
15
+ select_first_vs_detect: true
16
+ select_last_vs_reverse_detect: true
17
+ setter_vs_attr_writer: true
18
+ shuffle_first_vs_sample: true
19
+ sort_vs_sort_by: true
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
@@ -0,0 +1,28 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+ DisplayCopNames: true
7
+ DisplayStyleGuide: true
8
+ LineLength:
9
+ Max: 100
10
+ Layout/EmptyLinesAroundBlockBody:
11
+ Exclude:
12
+ - 'spec/**/**/*'
13
+ Layout/EmptyLinesAroundClassBody:
14
+ EnforcedStyle: empty_lines_except_namespace
15
+ Layout/EmptyLinesAroundModuleBody:
16
+ EnforcedStyle: empty_lines_except_namespace
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - 'spec/**/**/*'
20
+ - '*.gemspec'
21
+ RSpec/ExampleLength:
22
+ Enabled: false
23
+ Style/ClassAndModuleChildren:
24
+ Enabled: false
25
+ Style/Documentation:
26
+ Enabled: false
27
+ Style/ExpandPathArguments:
28
+ Enabled: false
@@ -0,0 +1,24 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5
6
+ - 2.6
7
+ - ruby-head
8
+ matrix:
9
+ fast_finish: true
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ before_install:
13
+ - gem update --system
14
+ - gem install bundler
15
+ install:
16
+ - bundle install --jobs=3 --retry=3
17
+ script:
18
+ - bundle exec rspec
19
+ - bundle exec rubocop
20
+ - bundle exec fasterer
21
+ notifications:
22
+ email: false
23
+ slack:
24
+ secure: J2Lyk75M2pDeL1+aQRDNfr1+/V4uulBOYpd0DggsY/geQMTTvv6VEb6HjRuPfP0T+JOHMaOmPee7Y1xL5HoDabdUn03RdFoR0MCoW9bG3ZeHoJHaZMJBiNBLx1hA6945v3hgWtCnYVG4iFmfDgD26fXHiZHsitgcZqmrmVuoT1rzjHnd913Z4cCk2bROBk8vzXRhx3ebfXH2pdhr8Rv04Fwqu0mRWZfG15+G28F13yB99oYQoyq+AdQfZVUxdsJHYLox3hQzsSuJ3Qc3SQtmh6z7x7BTNqdL3CrKK2b1iCdu1guz40f3bQV7NA9zeuf/X46DZPVGULb6IYsTKhpqq1cPg5PAZCqxbaED8/yCeXA30p7j71SjkC98V+JK3KEhjpfYdruxMe9j/8P3axmbr4Du17oFoNVtVfqab1DfEqMXtKxn5LDoseHKG+YqfEjmMUPE7ZntGDs8Lt/EYHPakV91azNwB3XMSRGH2Fn7YhsnFUsQPFHXtP47qecWDpSzLjFRWBE+IO706YIymflsYXlBGQq42WaiVSiDu20iUGBCQTxoAQg2sXJpYtimYl9SoXfHlzV6Cl0LBND7/da23eTEq3sxC7bqa/XEEpAcamWkWndREJqBZmwsmXOLMlJ8I8dZ7plzjcGFDJ3NXsOjTmGqFlexlxtX0/ciMkED1yQ=
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+ ## [1.0.0] - 2019-07-08
9
+ ### Added
10
+ - Initial project version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at j.gomez@drexed.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in lite-report.gemspec
6
+ gemspec
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lite-report (1.0.0)
5
+ activerecord
6
+ activerecord-import
7
+ deep_pluck
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (5.2.3)
13
+ actionview (= 5.2.3)
14
+ activesupport (= 5.2.3)
15
+ rack (~> 2.0)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
+ actionview (5.2.3)
20
+ activesupport (= 5.2.3)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.4)
23
+ rails-dom-testing (~> 2.0)
24
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
25
+ activemodel (5.2.3)
26
+ activesupport (= 5.2.3)
27
+ activerecord (5.2.3)
28
+ activemodel (= 5.2.3)
29
+ activesupport (= 5.2.3)
30
+ arel (>= 9.0)
31
+ activerecord-import (1.0.2)
32
+ activerecord (>= 3.2)
33
+ activesupport (5.2.3)
34
+ concurrent-ruby (~> 1.0, >= 1.0.2)
35
+ i18n (>= 0.7, < 2)
36
+ minitest (~> 5.1)
37
+ tzinfo (~> 1.1)
38
+ arel (9.0.0)
39
+ ast (2.4.0)
40
+ builder (3.2.3)
41
+ colorize (0.8.1)
42
+ concurrent-ruby (1.1.5)
43
+ crass (1.0.4)
44
+ database_cleaner (1.7.0)
45
+ deep_pluck (1.1.1)
46
+ activerecord (>= 3)
47
+ pluck_all (>= 1.2.3)
48
+ diff-lcs (1.3)
49
+ erubi (1.8.0)
50
+ fasterer (0.5.1)
51
+ colorize (~> 0.7)
52
+ ruby_parser (>= 3.13.0)
53
+ generator_spec (0.9.4)
54
+ activesupport (>= 3.0.0)
55
+ railties (>= 3.0.0)
56
+ i18n (1.6.0)
57
+ concurrent-ruby (~> 1.0)
58
+ jaro_winkler (1.5.3)
59
+ loofah (2.2.3)
60
+ crass (~> 1.0.2)
61
+ nokogiri (>= 1.5.9)
62
+ method_source (0.9.2)
63
+ mini_portile2 (2.4.0)
64
+ minitest (5.11.3)
65
+ nokogiri (1.10.3)
66
+ mini_portile2 (~> 2.4.0)
67
+ parallel (1.17.0)
68
+ parser (2.6.3.0)
69
+ ast (~> 2.4.0)
70
+ pluck_all (2.0.4)
71
+ activesupport (>= 3.0.0)
72
+ rack (2.0.7)
73
+ rack-test (1.1.0)
74
+ rack (>= 1.0, < 3)
75
+ rails-dom-testing (2.0.3)
76
+ activesupport (>= 4.2.0)
77
+ nokogiri (>= 1.6)
78
+ rails-html-sanitizer (1.0.4)
79
+ loofah (~> 2.2, >= 2.2.2)
80
+ railties (5.2.3)
81
+ actionpack (= 5.2.3)
82
+ activesupport (= 5.2.3)
83
+ method_source
84
+ rake (>= 0.8.7)
85
+ thor (>= 0.19.0, < 2.0)
86
+ rainbow (3.0.0)
87
+ rake (12.3.2)
88
+ ransack (2.1.1)
89
+ actionpack (>= 5.0)
90
+ activerecord (>= 5.0)
91
+ activesupport (>= 5.0)
92
+ i18n
93
+ rspec (3.8.0)
94
+ rspec-core (~> 3.8.0)
95
+ rspec-expectations (~> 3.8.0)
96
+ rspec-mocks (~> 3.8.0)
97
+ rspec-core (3.8.2)
98
+ rspec-support (~> 3.8.0)
99
+ rspec-expectations (3.8.4)
100
+ diff-lcs (>= 1.2.0, < 2.0)
101
+ rspec-support (~> 3.8.0)
102
+ rspec-mocks (3.8.1)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.8.0)
105
+ rspec-rails (3.8.2)
106
+ actionpack (>= 3.0)
107
+ activesupport (>= 3.0)
108
+ railties (>= 3.0)
109
+ rspec-core (~> 3.8.0)
110
+ rspec-expectations (~> 3.8.0)
111
+ rspec-mocks (~> 3.8.0)
112
+ rspec-support (~> 3.8.0)
113
+ rspec-support (3.8.2)
114
+ rubocop (0.72.0)
115
+ jaro_winkler (~> 1.5.1)
116
+ parallel (~> 1.10)
117
+ parser (>= 2.6)
118
+ rainbow (>= 2.2.2, < 4.0)
119
+ ruby-progressbar (~> 1.7)
120
+ unicode-display_width (>= 1.4.0, < 1.7)
121
+ rubocop-performance (1.4.0)
122
+ rubocop (>= 0.71.0)
123
+ rubocop-rspec (1.33.0)
124
+ rubocop (>= 0.60.0)
125
+ ruby-progressbar (1.10.1)
126
+ ruby_parser (3.13.1)
127
+ sexp_processor (~> 4.9)
128
+ sexp_processor (4.12.1)
129
+ sqlite3 (1.4.1)
130
+ thor (0.20.3)
131
+ thread_safe (0.3.6)
132
+ tzinfo (1.2.5)
133
+ thread_safe (~> 0.1)
134
+ unicode-display_width (1.6.0)
135
+
136
+ PLATFORMS
137
+ ruby
138
+
139
+ DEPENDENCIES
140
+ bundler
141
+ database_cleaner
142
+ fasterer
143
+ generator_spec
144
+ lite-report!
145
+ rake
146
+ ransack
147
+ rspec
148
+ rspec-rails
149
+ rubocop
150
+ rubocop-performance
151
+ rubocop-rspec
152
+ sqlite3
153
+
154
+ BUNDLED WITH
155
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Juan Gomez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,202 @@
1
+ # Lite::Report
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lite-report.svg)](http://badge.fury.io/rb/lite-report)
4
+ [![Build Status](https://travis-ci.org/drexed/lite-report.svg?branch=master)](https://travis-ci.org/drexed/lite-report)
5
+
6
+ Lite::Report is a library for importing and exporting Ruby and Rails objects to flat files and
7
+ vice versa. Usage of the report module has many options so it is best if you check out the specs
8
+ to see everything the library can do.
9
+
10
+ **NOTE:** If you are coming from `ActiveReport`, please read the [port](#port) section.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'lite-report'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install lite-report
27
+
28
+ ## Table of Contents
29
+
30
+ * [Configurations](#configurations)
31
+ * [Array](#array)
32
+ * [Hash](#hash)
33
+ * [Record](#record)
34
+ * [Stream](#stream)
35
+ * [Port](#port)
36
+
37
+ ## Configurations
38
+
39
+ `rails g lite:report:install` will generate the following file:
40
+ `../config/initalizers/lite-report.rb`
41
+
42
+ Place your default configs in this file.
43
+
44
+ ```ruby
45
+ Lite::Report.configure do |config|
46
+ config.csv_options = {}
47
+ config.data_options = {}
48
+ config.import_options = {}
49
+ end
50
+ ```
51
+
52
+ ## Array
53
+
54
+ ```ruby
55
+ data = [
56
+ ['James Jones', 39, 'male', ...],
57
+ ['Pamela Anderson', 52, 'female', ...],
58
+ ['Dwayne Wade', 21, 'male', ...]
59
+ ]
60
+
61
+ # Convert array of arrays to CSV file
62
+ Lite::Report::Array.export(
63
+ data,
64
+ data_options: {
65
+ only: ['Age', 'Sex']
66
+ },
67
+ csv_options: {
68
+ write_headers: true,
69
+ headers: ['Name', 'Age', 'Sex', ...]
70
+ }
71
+ )
72
+
73
+ # Convert CSV file to an array of arrays
74
+ Lite::Report::Array.import(
75
+ 'path/to/file.csv',
76
+ data_options: {
77
+ except: ['Age', 'Sex']
78
+ },
79
+ csv_options: {
80
+ return_headers: true,
81
+ headers: ['Name', 'Age', 'Sex', ...]
82
+ }
83
+ )
84
+ ```
85
+
86
+ ## Hash
87
+
88
+ ```ruby
89
+ data = [
90
+ { 'Name' => 'James Jones', 'Age' => 39, 'Sex' => 'male', ...],
91
+ { 'Name' => 'Pamela Anderson', 'Age' => 52, 'Sex' => 'female', ...],
92
+ { 'Name' => 'Dwayne Wade', 'Age' => 21, 'Sex' => 'male', ...]
93
+ ]
94
+
95
+ # Convert array of hashes to CSV file
96
+ Lite::Report::Hash.export(
97
+ data,
98
+ data_options: {
99
+ only: ['Age', 'Sex']
100
+ },
101
+ csv_options: {
102
+ write_headers: true,
103
+ headers: ['Name', 'Age', 'Sex', ...]
104
+ }
105
+ )
106
+
107
+ # Convert CSV file to an array of hashes
108
+ Lite::Report::Hash.import(
109
+ 'path/to/file.csv',
110
+ data_options: {
111
+ except: ['Age', 'Sex']
112
+ },
113
+ csv_options: {
114
+ return_headers: true,
115
+ headers: ['Name', 'Age', 'Sex', ...]
116
+ }
117
+ )
118
+ ```
119
+
120
+ ## Record
121
+
122
+ ```ruby
123
+ data = User.where(age: 20..29)
124
+
125
+ # Convert array/relation/ransack of records to CSV file
126
+ Lite::Report::Record.export(
127
+ data,
128
+ data_options: {
129
+ only: [:age, :sex]
130
+ },
131
+ csv_options: {
132
+ write_headers: true,
133
+ headers: ['Name', 'Age', 'Sex', ...]
134
+ }
135
+ )
136
+
137
+ # Convert CSV file to an array of records
138
+ Lite::Report::Record.import(
139
+ 'path/to/file.csv',
140
+ data_options: {
141
+ klass: User,
142
+ except: [:age, :sex]
143
+ }
144
+ )
145
+ ```
146
+
147
+ ## Stream
148
+
149
+ Stream is great option for preventing browser timeouts of downloading large CSV files by chunking
150
+ the results via an enumerator.
151
+
152
+ ```ruby
153
+ class StreamingController < ApplicationController
154
+
155
+ def download
156
+ headers.delete("Content-Length") # Tell Rack to stream the content
157
+ headers["Cache-Control"] = "no-cache" # Don't cache anything from this generated endpoint
158
+ headers["Content-Type"] = "text/csv" # Tell the browser this is a CSV file
159
+ headers["X-Accel-Buffering"] = "no" # Don't buffer when going through proxy servers
160
+
161
+ # Make the file download with a specific filename
162
+ headers["Content-Disposition"] = "attachment; filename=\"example.csv\""
163
+
164
+ self.response_body = report_body # Set an Enumerator as the body
165
+ response.status = 200 # Set the status to success
166
+ end
167
+
168
+ private
169
+
170
+ def report_body
171
+ Lite::Report::Hash.export(
172
+ data,
173
+ csv_options: { stream: true }
174
+ )
175
+ end
176
+
177
+ end
178
+ ```
179
+
180
+ ## Port
181
+
182
+ `Lite::Report` is NOT a compatible port of [ActiveReport](https://github.com/drexed/active_report).
183
+
184
+ Please read the docs and go through the specs to view many examples.
185
+
186
+ ## Development
187
+
188
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
189
+
190
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
191
+
192
+ ## Contributing
193
+
194
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lite-report. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
195
+
196
+ ## License
197
+
198
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
199
+
200
+ ## Code of Conduct
201
+
202
+ Everyone interacting in the Lite::Report project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lite-report/blob/master/CODE_OF_CONDUCT.md).