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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc93d81b62487eb830eb1dc170d85e0190744c35fdaadabb7c0b7e90b83993a
4
- data.tar.gz: b1c554539e5acf746f1161e7d39540f2965100b958acf47713552f39b2b24806
3
+ metadata.gz: 2e93417de22977ce483ce4ebddcdfcf72831e853d76136b98ea029c162752796
4
+ data.tar.gz: f9da1cd2c6aeaf86b848adc2a7042dc5f1a584e6d4bfc5467db57e378427c96a
5
5
  SHA512:
6
- metadata.gz: 4b7b98e29de827fcf9659983b290710ecdd08befc61480916f57e0dc2f90e7c17ac50e9269a3165a6a618a486863ca8bffa02b39c768e4c15493feac19d43c1e
7
- data.tar.gz: 935db432412bca80fab78186cb9a945dc9d90b682b1d638ef3246d942848684d0266276b11645c86c3acacec48244ad708eb4f6ccd3bbd66e4ad96c9d831ee0f
6
+ metadata.gz: f8665373ecedda065531a06d42ea6af146fcc463e8e05d5b286d0bf1d66228d223215f6811f0fa00bf2bcd8cd58f863e451c75cdc9a5121b819462aabfc6c63c
7
+ data.tar.gz: b0ec658eb4f68416100c0bdd242e16c44b16b090ace5d74bff7fbdfb3b1be2a622c3bcec9d9b02824a0d5946ecea3f8d4887b8d4443e716cf92680abbf99d1a8
data/.reek CHANGED
@@ -15,6 +15,8 @@ InstanceVariableAssumption:
15
15
  enabled: false
16
16
  LongParameterList:
17
17
  enabled: false
18
+ ManualDispatch:
19
+ enabled: false
18
20
  NestedIterators:
19
21
  max_allowed_nesting: 2
20
22
  NilCheck:
@@ -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[:options] ||= csv_options
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?
@@ -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 !@data.is_a?(ActiveRecord::Relation) && @data.try(:superclass) == ActiveRecord::Base
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 @opts[:model].nil? || (@opts[:model].superclass != ActiveRecord::Base)
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 do |row|
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 do |row|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveReport
4
- VERSION ||= '5.2.3'
4
+ VERSION ||= '5.2.4'
5
5
  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.3
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-23 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord