activekit 0.5.0.dev3 → 0.5.0.dev4

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: eff7a049cd21979e76253d095e0d0ba722b289370a15426cf4b87c922d2bab66
4
+ data.tar.gz: 27b310f65547d08961b9044fe43bc606cfb78f0766487052c9488a2fa3e78ed8
5
5
  SHA512:
6
- metadata.gz: 971bc6562a3d04df66068fb6d498ccc0b67de160a2d0d02c7e6d62d4c0d6e60a0196f4c888f0edeb189e5c310ea4d485c74d095182d37d33c59bb080bd226746
7
- data.tar.gz: 75394d757e7997b919c73e9ecfbde9531754fee398e985c6f5919f12dee63e795b658271e64db3301f1d415e391a2b3ddfd26edd7bd38eab400b83951ba39466
6
+ metadata.gz: ce4750f37977c8e2a63a6ec85ad4def621877f3789eb64e598d214066f840463c3cbe7a60b5e4853d9a639a2f83cd480a953c0436535547acf8a9b55b5113de9
7
+ data.tar.gz: c3813bb2b5df232389c25c8bc0ecf35f5875d6fdc34060d67993643f728bca9c0b6d0d81c85abed349dfb52bef8b0ac2a392ce88ce72a37adc722c3d533e1f64
@@ -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 = {}
@@ -39,26 +37,28 @@ module ActiveKit
39
37
  def define_describer_method(kind:, name:)
40
38
  case kind
41
39
  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) }
40
+ @current_class.class_eval do
41
+ define_singleton_method name do
42
+ describer = exporter.find_describer_by(describer_name: name)
43
+ raise "could not find describer for the describer name '#{name}'" unless describer.present?
44
+
45
+ # The 'all' relation must be captured outside the Enumerator,
46
+ # else it will get reset to all the records of the class.
47
+ all_activerecord_relation = all.includes(describer.includes)
48
+
49
+ Enumerator.new do |yielder|
50
+ ActiveRecord::Base.connected_to(role: :writing, shard: describer.database.call) do
51
+ exporting = exporter.new_exporting(describer: describer)
52
+
53
+ # Add the headings.
54
+ yielder << CSV.generate_line(exporting.headings) if exporting.headings?
55
+
56
+ # Add the values.
57
+ # find_each will ignore any order if set earlier.
58
+ all_activerecord_relation.find_each do |record|
59
+ lines = exporting.lines_for(record: record)
60
+ lines.each { |line| yielder << CSV.generate_line(line) }
61
+ end
62
62
  end
63
63
  end
64
64
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.5.0.dev3'
2
+ VERSION = '0.5.0.dev4'
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.dev4
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource