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 +4 -4
- data/lib/active_kit/export/exporter.rb +23 -25
- 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: '068662b0f0144c92e082fc2a3e5002695a090dc1a4547a79889a945e739b7593'
|
4
|
+
data.tar.gz: a782fef4b69dfd9df1869c78e5826c8699adaf5339ca066ca48531ba391f66c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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(
|
40
|
-
case kind
|
38
|
+
def define_describer_method(describer)
|
39
|
+
case describer.kind
|
41
40
|
when :csv
|
42
|
-
|
43
|
-
describer
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
data/lib/active_kit/version.rb
CHANGED