activekit 0.5.0.dev3 → 0.5.0.dev5

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: b32a04bec4de6085fcce1d004a96792b2fdfd9166d55cb9a2584a719be226a45
4
- data.tar.gz: 4dc7aa2af40b73b744225a2509a8fb8447eaa94a3b02fafd893889fd02673780
3
+ metadata.gz: '068662b0f0144c92e082fc2a3e5002695a090dc1a4547a79889a945e739b7593'
4
+ data.tar.gz: a782fef4b69dfd9df1869c78e5826c8699adaf5339ca066ca48531ba391f66c5
5
5
  SHA512:
6
- metadata.gz: 971bc6562a3d04df66068fb6d498ccc0b67de160a2d0d02c7e6d62d4c0d6e60a0196f4c888f0edeb189e5c310ea4d485c74d095182d37d33c59bb080bd226746
7
- data.tar.gz: 75394d757e7997b919c73e9ecfbde9531754fee398e985c6f5919f12dee63e795b658271e64db3301f1d415e391a2b3ddfd26edd7bd38eab400b83951ba39466
6
+ metadata.gz: c0b3d0c3bd09b6d4de855c802ca0e4e47485a3fa727331088ff9b0ed3f21bf701485f6f15addd0d4b16cabad7442cb5d8d3f256e5b9d524ea36a0c0b2e58ce70
7
+ data.tar.gz: 6d74e3e1775bd54f86022f40815593f3e0c60d6fdbb3fed1d14054c633f4af2b1456d1ad03018aaf2b9698fd0aadc123c3884edcd996af3f1ad7405238dcc5aa
@@ -1,8 +1,6 @@
1
1
  module ActiveKit
2
2
  module Export
3
3
  class Exporter
4
- attr_reader :describers
5
-
6
4
  def initialize(current_class:)
7
5
  @current_class = current_class
8
6
  @describers = {}
@@ -15,7 +13,8 @@ module ActiveKit
15
13
  unless find_describer_by(describer_name: name)
16
14
  options.store(:attributes, {})
17
15
  @describers.store(name, options)
18
- define_describer_method(kind: options[:kind], name: name)
16
+ describer = find_describer_by(describer_name: name)
17
+ define_describer_method(describer)
19
18
  end
20
19
  end
21
20
 
@@ -36,29 +35,28 @@ module ActiveKit
36
35
 
37
36
  private
38
37
 
39
- def define_describer_method(kind:, name:)
40
- case kind
38
+ def define_describer_method(describer)
39
+ case describer.kind
41
40
  when :csv
42
- define_singleton_method name do
43
- describer = exporter.find_describer_by(describer_name: name)
44
- raise "could not find describer for the describer name '#{name}'" unless describer.present?
45
-
46
- # The 'all' relation must be captured outside the Enumerator,
47
- # else it will get reset to all the records of the class.
48
- all_activerecord_relation = all.includes(describer.includes)
49
-
50
- Enumerator.new do |yielder|
51
- ActiveRecord::Base.connected_to(role: :writing, shard: describer.database.call) do
52
- exporting = exporter.new_exporting(describer: describer)
53
-
54
- # Add the headings.
55
- yielder << CSV.generate_line(exporting.headings) if exporting.headings?
56
-
57
- # Add the values.
58
- # find_each will ignore any order if set earlier.
59
- all_activerecord_relation.find_each do |record|
60
- lines = exporting.lines_for(record: record)
61
- lines.each { |line| yielder << CSV.generate_line(line) }
41
+ @current_class.class_eval do
42
+ define_singleton_method describer.name do
43
+ # The 'all' relation must be captured outside the Enumerator,
44
+ # else it will get reset to all the records of the class.
45
+ all_activerecord_relation = all.includes(describer.includes)
46
+
47
+ Enumerator.new do |yielder|
48
+ ActiveRecord::Base.connected_to(role: :writing, shard: describer.database.call) do
49
+ exporting = exporter.new_exporting(describer: describer)
50
+
51
+ # Add the headings.
52
+ yielder << CSV.generate_line(exporting.headings) if exporting.headings?
53
+
54
+ # Add the values.
55
+ # find_each will ignore any order if set earlier.
56
+ all_activerecord_relation.find_each do |record|
57
+ lines = exporting.lines_for(record: record)
58
+ lines.each { |line| yielder << CSV.generate_line(line) }
59
+ end
62
60
  end
63
61
  end
64
62
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.5.0.dev3'
2
+ VERSION = '0.5.0.dev5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activekit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.dev3
4
+ version: 0.5.0.dev5
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource