activekit 0.5.0.dev4 → 0.5.0.dev6
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/exportable.rb +2 -2
- data/lib/active_kit/export/exporter.rb +30 -35
- 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: 4be51587fe2bc2ef391a14a432ab155a50489acd765845dd88212c56bfbd5328
|
4
|
+
data.tar.gz: 9839b9510d9610ca93573dda2e4e83b05b1cd1aa2c9902ff96f2dc83d2385af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5769a0034e566bbe56280904e96cb240e32f309191f7b6e1d20368d8faaf67ea348b90bf19295e810214a845fe639fae2494629b2c0bf3444fdff45d77710b54
|
7
|
+
data.tar.gz: 0e025b165752e96fae3b839420134e111a9c1f264176bafdaff3d8174e3ea9514f59833873bd5f587f8db4a56497ec9be10416ee8112d7abf848d815a1a199de
|
@@ -14,11 +14,11 @@ module ActiveKit
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def export_describer(name, **options)
|
17
|
-
exporter.
|
17
|
+
exporter.create_describer(name, options)
|
18
18
|
end
|
19
19
|
|
20
20
|
def export_attribute(name, **options)
|
21
|
-
exporter.
|
21
|
+
exporter.create_attribute(name, options)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -6,22 +6,28 @@ module ActiveKit
|
|
6
6
|
@describers = {}
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def create_describer(name, options)
|
10
10
|
name = name.to_sym
|
11
11
|
options.deep_symbolize_keys!
|
12
12
|
|
13
13
|
unless find_describer_by(describer_name: name)
|
14
14
|
options.store(:attributes, {})
|
15
15
|
@describers.store(name, options)
|
16
|
-
|
16
|
+
if describer = find_describer_by(describer_name: name)
|
17
|
+
@current_class.class_eval do
|
18
|
+
define_singleton_method describer.name do
|
19
|
+
exporter.describer_method(describer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
def
|
21
|
-
create_export_describer(:to_csv, kind: :csv, database: -> { ActiveRecord::Base.connection_db_config.database.to_sym }) unless @describers.present?
|
22
|
-
|
26
|
+
def create_attribute(name, options)
|
23
27
|
options.deep_symbolize_keys!
|
24
28
|
|
29
|
+
create_describer(:to_csv, kind: :csv, database: -> { ActiveRecord::Base.connection_db_config.database.to_sym }) unless @describers.present?
|
30
|
+
|
25
31
|
describer_names = Array(options.delete(:describers))
|
26
32
|
describer_names = @describers.keys if describer_names.blank?
|
27
33
|
|
@@ -32,43 +38,32 @@ module ActiveKit
|
|
32
38
|
end
|
33
39
|
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
def define_describer_method(kind:, name:)
|
38
|
-
case kind
|
41
|
+
def describer_method(describer)
|
42
|
+
case describer.kind
|
39
43
|
when :csv
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
end
|
44
|
+
# The 'all' relation must be captured outside the Enumerator,
|
45
|
+
# else it will get reset to all the records of the class.
|
46
|
+
all_activerecord_relation = all.includes(describer.includes)
|
47
|
+
|
48
|
+
Enumerator.new do |yielder|
|
49
|
+
ActiveRecord::Base.connected_to(role: :writing, shard: describer.database.call) do
|
50
|
+
exporting = Exporting.new(describer: describer)
|
51
|
+
|
52
|
+
# Add the headings.
|
53
|
+
yielder << CSV.generate_line(exporting.headings) if exporting.headings?
|
54
|
+
|
55
|
+
# Add the values.
|
56
|
+
# find_each will ignore any order if set earlier.
|
57
|
+
all_activerecord_relation.find_each do |record|
|
58
|
+
lines = exporting.lines_for(record: record)
|
59
|
+
lines.each { |line| yielder << CSV.generate_line(line) }
|
63
60
|
end
|
64
61
|
end
|
65
62
|
end
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
|
-
|
70
|
-
Exporting.new(describer: describer)
|
71
|
-
end
|
66
|
+
private
|
72
67
|
|
73
68
|
def find_describer_by(describer_name:)
|
74
69
|
describer_options = @describers.dig(describer_name)
|
data/lib/active_kit/version.rb
CHANGED