active_report 5.3.0 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.irbrc +44 -0
- data/.rubocop.yml +2 -2
- data/.travis.yml +10 -10
- data/CODE_OF_CONDUCT.md +13 -0
- data/README.md +1 -1
- data/bin/console +0 -0
- data/bin/rake +0 -0
- data/lib/active_report/base.rb +20 -10
- data/lib/active_report/configuration.rb +1 -1
- data/lib/active_report/record.rb +11 -5
- data/lib/active_report/version.rb +1 -1
- data/lib/generators/active_report/templates/install.rb +1 -1
- metadata +5 -4
- data/.coveralls.yml +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfb1f6cdec8dbfdd4ac3be83ece89d1ba4e1cc6e2bb584c672c7667059a28d72
|
4
|
+
data.tar.gz: 48912ded4e124dd223c26d930d620c1ccfc37607e9789b228bd0e9aeb32febcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0f2a0344c1856d35a995acf75a8c8f2a5458adc807b8230b8ff6488cc4361f95200ebe8d8c6fbb8e1aecdea5ad803fc1764bb268ed002ead7c5ba0827e084d0
|
7
|
+
data.tar.gz: 4ca7543205dfc4ca8133978a5d9eb0cc91622ec9d684e5e3fc88b85af532aa3f0e072e5613a371b96add25314c2d8848cbc5684fa601399ff1d5d65f3966e951
|
data/.gitignore
CHANGED
data/.irbrc
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Awesome print
|
4
|
+
begin
|
5
|
+
require 'awesome_print'
|
6
|
+
|
7
|
+
AwesomePrint.irb!
|
8
|
+
rescue LoadError => err
|
9
|
+
warn "Couldn't load awesome_print: #{err}"
|
10
|
+
end
|
11
|
+
|
12
|
+
# IRB
|
13
|
+
require 'irb/completion'
|
14
|
+
|
15
|
+
ARGV.concat %w[--readline --prompt-mode simple]
|
16
|
+
|
17
|
+
IRB.conf[:PROMPT_MODE] = :SIMPLE
|
18
|
+
IRB.conf[:EVAL_HISTORY] = 1000
|
19
|
+
IRB.conf[:SAVE_HISTORY] = 1000
|
20
|
+
IRB.conf[:HISTORY_FILE] = File.expand_path('.irbrc_history')
|
21
|
+
|
22
|
+
# Rails
|
23
|
+
railsrc_path = File.expand_path('.irbrc_rails')
|
24
|
+
|
25
|
+
if (ENV['RAILS_ENV'] || defined?(Rails)) && File.exist?(railsrc_path)
|
26
|
+
begin
|
27
|
+
load railsrc_path
|
28
|
+
rescue Exception => err
|
29
|
+
warn "Could not load: #{railsrc_path} because of #{err}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Object
|
34
|
+
class Object
|
35
|
+
|
36
|
+
def interesting_methods
|
37
|
+
case self.class
|
38
|
+
when Class then public_methods.sort - Object.public_methods
|
39
|
+
when Module then public_methods.sort - Module.public_methods
|
40
|
+
else public_methods.sort - Object.new.public_methods
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/.rubocop.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
DisplayCopNames: true
|
3
3
|
DisplayStyleGuide: true
|
4
|
-
TargetRubyVersion: 2.
|
4
|
+
TargetRubyVersion: 2.5
|
5
5
|
Exclude:
|
6
6
|
- 'spec/**/**/*'
|
7
7
|
Layout/EmptyLinesAroundClassBody:
|
@@ -10,7 +10,7 @@ Layout/EmptyLinesAroundModuleBody:
|
|
10
10
|
Enabled: false
|
11
11
|
LineLength:
|
12
12
|
Max: 100
|
13
|
-
Lint/
|
13
|
+
Lint/RescueException:
|
14
14
|
Enabled: false
|
15
15
|
Metrics/AbcSize:
|
16
16
|
Enabled: false
|
data/.travis.yml
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
- sudo apt-get install libxml2-dev
|
3
|
-
cache: bundler
|
1
|
+
sudo: false
|
4
2
|
language: ruby
|
5
|
-
notifications:
|
6
|
-
email:
|
7
|
-
recipients:
|
8
|
-
- j.gomez@drexed.com
|
9
|
-
on_failure: change
|
10
|
-
on_success: never
|
11
3
|
rvm:
|
12
4
|
- ruby-head
|
13
|
-
|
5
|
+
before_install:
|
6
|
+
- sudo apt-get install libxml2-dev
|
7
|
+
- gem update --system
|
8
|
+
- gem install bundler
|
9
|
+
- bundle install
|
10
|
+
script:
|
11
|
+
- bundle exec rake
|
12
|
+
notifications:
|
13
|
+
disable: true
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ Or install it yourself as:
|
|
37
37
|
```ruby
|
38
38
|
ActiveReport.configure do |config|
|
39
39
|
config.csv_force_encoding = true
|
40
|
-
config.csv_options = {
|
40
|
+
config.csv_options = { external_encoding: 'ISO-8859-1', internal_encoding: 'UTF-8' }
|
41
41
|
config.import_adapter = 'mysql2_adapter'
|
42
42
|
config.import_options = { validate: false, on_duplicate_key_ignore: true }
|
43
43
|
end
|
data/bin/console
CHANGED
File without changes
|
data/bin/rake
CHANGED
File without changes
|
data/lib/active_report/base.rb
CHANGED
@@ -52,17 +52,21 @@ class ActiveReport::Base
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def active_record_table_class?(object)
|
55
|
-
return if object.nil? ||
|
55
|
+
return if object.nil? || active_relation_object?(object)
|
56
56
|
|
57
|
-
object.respond_to?(:table_name) ||
|
57
|
+
object.respond_to?(:table_name) || ransack_object?(object)
|
58
58
|
end
|
59
59
|
|
60
60
|
def active_record_column_names(object)
|
61
|
-
return object.klass.column_names if
|
61
|
+
return object.klass.column_names if ransack_object?(object)
|
62
62
|
|
63
63
|
object.column_names
|
64
64
|
end
|
65
65
|
|
66
|
+
def active_relation_object?(object)
|
67
|
+
object.is_a?(ActiveRecord::Relation)
|
68
|
+
end
|
69
|
+
|
66
70
|
def encode_to_utf8(line)
|
67
71
|
line.map do |chr|
|
68
72
|
next if chr.nil?
|
@@ -88,6 +92,14 @@ class ActiveReport::Base
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
95
|
+
def filter_values(data)
|
96
|
+
filter(data).values
|
97
|
+
end
|
98
|
+
|
99
|
+
def filter_humanize_keys(data)
|
100
|
+
filter(data.first).collect { |key, _| humanize(key) }
|
101
|
+
end
|
102
|
+
|
91
103
|
def humanize(object)
|
92
104
|
object.to_s.tr('_', ' ').capitalize
|
93
105
|
end
|
@@ -100,13 +112,13 @@ class ActiveReport::Base
|
|
100
112
|
[object].compact
|
101
113
|
end
|
102
114
|
|
103
|
-
# rubocop:disable Security/Eval
|
115
|
+
# rubocop:disable Security/Eval
|
104
116
|
def metaform(value)
|
105
117
|
eval(value.to_s)
|
106
118
|
rescue Exception
|
107
119
|
value
|
108
120
|
end
|
109
|
-
# rubocop:enable Security/Eval
|
121
|
+
# rubocop:enable Security/Eval
|
110
122
|
|
111
123
|
def metaform_array(data)
|
112
124
|
data.map { |val| metaform(val) }
|
@@ -146,12 +158,10 @@ class ActiveReport::Base
|
|
146
158
|
data.first.is_a?(Array) ? data : merge(data)
|
147
159
|
end
|
148
160
|
|
149
|
-
def
|
150
|
-
|
151
|
-
end
|
161
|
+
def ransack_object?(object)
|
162
|
+
return false unless defined?(::Ransack)
|
152
163
|
|
153
|
-
|
154
|
-
filter(data.first).collect { |key, _| humanize(key) }
|
164
|
+
object.is_a?(::Ransack::Search)
|
155
165
|
end
|
156
166
|
|
157
167
|
end
|
@@ -7,7 +7,7 @@ module ActiveReport
|
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@csv_force_encoding = true
|
10
|
-
@csv_options = {
|
10
|
+
@csv_options = { external_encoding: 'ISO-8859-1', internal_encoding: 'UTF-8' }
|
11
11
|
@import_adapter = 'mysql2_adapter'
|
12
12
|
@import_options = { validate: false, on_duplicate_key_ignore: true }
|
13
13
|
end
|
data/lib/active_report/record.rb
CHANGED
@@ -2,7 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'activerecord-import'
|
4
4
|
require 'activerecord-import/base'
|
5
|
-
|
5
|
+
|
6
|
+
begin
|
7
|
+
require "activerecord-import/active_record/adapters/#{ActiveReport.configuration.import_adapter}"
|
8
|
+
rescue Gem::LoadError
|
9
|
+
require 'activerecord-import/active_record/adapters/sqlite3_adapter'
|
10
|
+
end
|
11
|
+
|
6
12
|
require 'json'
|
7
13
|
|
8
14
|
class ActiveReport::Record < ActiveReport::Base
|
@@ -12,10 +18,9 @@ class ActiveReport::Record < ActiveReport::Base
|
|
12
18
|
|
13
19
|
if active_record_table_class?(@data)
|
14
20
|
@opts[:headers] = (@opts[:headers] || humanize_values(active_record_column_names(@data)))
|
15
|
-
|
16
21
|
@opts[:stream] ? export_stream : export_csv
|
17
22
|
else
|
18
|
-
@data = if @data
|
23
|
+
@data = if active_relation_object?(@data)
|
19
24
|
JSON.parse(@data.to_json).flatten
|
20
25
|
else
|
21
26
|
merge(@data.attributes)
|
@@ -54,10 +59,11 @@ class ActiveReport::Record < ActiveReport::Base
|
|
54
59
|
private
|
55
60
|
|
56
61
|
def export_csv
|
57
|
-
@data = @data.result if @data
|
62
|
+
@data = @data.result if ransack_object?(@data)
|
58
63
|
|
59
64
|
CSV.generate(@opts[:options]) do |csv|
|
60
65
|
csv << @opts[:headers]
|
66
|
+
|
61
67
|
@data.find_each(find_each_options) do |row|
|
62
68
|
csv << filter_values(row.attributes)
|
63
69
|
end
|
@@ -65,7 +71,7 @@ class ActiveReport::Record < ActiveReport::Base
|
|
65
71
|
end
|
66
72
|
|
67
73
|
def export_stream
|
68
|
-
@data = @data.result if @data
|
74
|
+
@data = @data.result if ransack_object?(@data)
|
69
75
|
|
70
76
|
Enumerator.new do |csv|
|
71
77
|
csv << CSV.generate_line(@opts[:headers])
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
ActiveReport.configure do |config|
|
4
4
|
config.csv_force_encoding = true
|
5
|
-
config.csv_options = {
|
5
|
+
config.csv_options = { external_encoding: 'ISO-8859-1', internal_encoding: 'UTF-8' }
|
6
6
|
config.import_adapter = 'mysql2_adapter'
|
7
7
|
config.import_options = { validate: false, on_duplicate_key_ignore: true }
|
8
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.4.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: 2018-
|
11
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -173,13 +173,14 @@ extensions: []
|
|
173
173
|
extra_rdoc_files: []
|
174
174
|
files:
|
175
175
|
- ".DS_Store"
|
176
|
-
- ".coveralls.yml"
|
177
176
|
- ".fasterer.yml"
|
178
177
|
- ".gitignore"
|
178
|
+
- ".irbrc"
|
179
179
|
- ".reek.yml"
|
180
180
|
- ".rspec"
|
181
181
|
- ".rubocop.yml"
|
182
182
|
- ".travis.yml"
|
183
|
+
- CODE_OF_CONDUCT.md
|
183
184
|
- Gemfile
|
184
185
|
- LICENSE.txt
|
185
186
|
- README.md
|
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
218
219
|
version: '0'
|
219
220
|
requirements: []
|
220
221
|
rubyforge_project:
|
221
|
-
rubygems_version: 2.7.
|
222
|
+
rubygems_version: 2.7.8
|
222
223
|
signing_key:
|
223
224
|
specification_version: 4
|
224
225
|
summary: Gem for exporting/importing ruby objects to flat files vice versa.
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
service_name: travis-ci
|