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 +4 -4
- data/lib/active_kit/export/exporter.rb +22 -22
- data/lib/active_kit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff7a049cd21979e76253d095e0d0ba722b289370a15426cf4b87c922d2bab66
|
4
|
+
data.tar.gz: 27b310f65547d08961b9044fe43bc606cfb78f0766487052c9488a2fa3e78ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
data/lib/active_kit/version.rb
CHANGED