active_report 5.2.3 → 5.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.reek +2 -0
- data/lib/active_report/base.rb +11 -1
- data/lib/active_report/record.rb +10 -6
- data/lib/active_report/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e93417de22977ce483ce4ebddcdfcf72831e853d76136b98ea029c162752796
|
4
|
+
data.tar.gz: f9da1cd2c6aeaf86b848adc2a7042dc5f1a584e6d4bfc5467db57e378427c96a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8665373ecedda065531a06d42ea6af146fcc463e8e05d5b286d0bf1d66228d223215f6811f0fa00bf2bcd8cd58f863e451c75cdc9a5121b819462aabfc6c63c
|
7
|
+
data.tar.gz: b0ec658eb4f68416100c0bdd242e16c44b16b090ace5d74bff7fbdfb3b1be2a622c3bcec9d9b02824a0d5946ecea3f8d4887b8d4443e716cf92680abbf99d1a8
|
data/.reek
CHANGED
data/lib/active_report/base.rb
CHANGED
@@ -9,7 +9,7 @@ class ActiveReport::Base
|
|
9
9
|
@opts = opts
|
10
10
|
|
11
11
|
%i[except only].each { |key| @opts[key] = munge(@opts[key]) }
|
12
|
-
@opts[
|
12
|
+
{ batch_size: 1_000, options: csv_options }.each { |key, val| @opts[key] ||= val }
|
13
13
|
end
|
14
14
|
|
15
15
|
def csv_options
|
@@ -45,6 +45,16 @@ class ActiveReport::Base
|
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
|
+
def active_record_table_object?(object)
|
49
|
+
return if object.nil?
|
50
|
+
!object.respond_to?(:table_name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def active_record_table_class?(object)
|
54
|
+
return if object.nil? || object.is_a?(ActiveRecord::Relation)
|
55
|
+
object.respond_to?(:table_name)
|
56
|
+
end
|
57
|
+
|
48
58
|
def encode_to_utf8(line)
|
49
59
|
line.map do |chr|
|
50
60
|
next if chr.nil?
|
data/lib/active_report/record.rb
CHANGED
@@ -7,11 +7,10 @@ require 'json'
|
|
7
7
|
|
8
8
|
class ActiveReport::Record < ActiveReport::Base
|
9
9
|
|
10
|
-
# rubocop:disable Metrics/PerceivedComplexity
|
11
10
|
def export
|
12
11
|
%i[except only].each { |key| @opts[key] = @opts[key].map(&:to_s) }
|
13
12
|
|
14
|
-
if
|
13
|
+
if active_record_table_class?(@data)
|
15
14
|
@opts[:headers] = (@opts[:headers] || humanize_values(@data.column_names))
|
16
15
|
|
17
16
|
@opts[:stream] ? export_stream : export_csv
|
@@ -25,10 +24,9 @@ class ActiveReport::Record < ActiveReport::Base
|
|
25
24
|
ActiveReport::Hash.export(@data, @opts)
|
26
25
|
end
|
27
26
|
end
|
28
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
29
27
|
|
30
28
|
def import
|
31
|
-
if
|
29
|
+
if active_record_table_object?(@opts[:model])
|
32
30
|
raise ArgumentError,
|
33
31
|
'Model must be an ActiveRecord::Base object.'
|
34
32
|
end
|
@@ -59,7 +57,10 @@ class ActiveReport::Record < ActiveReport::Base
|
|
59
57
|
CSV.generate(@opts[:options]) do |csv|
|
60
58
|
csv << @opts[:headers]
|
61
59
|
|
62
|
-
@data.find_each
|
60
|
+
@data.find_each(start: @opts[:start],
|
61
|
+
finish: @opts[:finish],
|
62
|
+
batch_size: @opts[:batch_size],
|
63
|
+
error_on_ignore: @opts[:error_on_ignore]) do |row|
|
63
64
|
csv << filter_values(row.attributes)
|
64
65
|
end
|
65
66
|
end
|
@@ -69,7 +70,10 @@ class ActiveReport::Record < ActiveReport::Base
|
|
69
70
|
Enumerator.new do |csv|
|
70
71
|
csv << CSV.generate_line(@opts[:headers])
|
71
72
|
|
72
|
-
@data.find_each
|
73
|
+
@data.find_each(start: @opts[:start],
|
74
|
+
finish: @opts[:finish],
|
75
|
+
batch_size: @opts[:batch_size],
|
76
|
+
error_on_ignore: @opts[:error_on_ignore]) do |row|
|
73
77
|
csv << CSV.generate_line(filter_values(row.attributes))
|
74
78
|
end
|
75
79
|
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.2.
|
4
|
+
version: 5.2.4
|
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-05-
|
11
|
+
date: 2018-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|