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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eff7a049cd21979e76253d095e0d0ba722b289370a15426cf4b87c922d2bab66
4
- data.tar.gz: 27b310f65547d08961b9044fe43bc606cfb78f0766487052c9488a2fa3e78ed8
3
+ metadata.gz: 4be51587fe2bc2ef391a14a432ab155a50489acd765845dd88212c56bfbd5328
4
+ data.tar.gz: 9839b9510d9610ca93573dda2e4e83b05b1cd1aa2c9902ff96f2dc83d2385af4
5
5
  SHA512:
6
- metadata.gz: ce4750f37977c8e2a63a6ec85ad4def621877f3789eb64e598d214066f840463c3cbe7a60b5e4853d9a639a2f83cd480a953c0436535547acf8a9b55b5113de9
7
- data.tar.gz: c3813bb2b5df232389c25c8bc0ecf35f5875d6fdc34060d67993643f728bca9c0b6d0d81c85abed349dfb52bef8b0ac2a392ce88ce72a37adc722c3d533e1f64
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.create_export_describer(name, options)
17
+ exporter.create_describer(name, options)
18
18
  end
19
19
 
20
20
  def export_attribute(name, **options)
21
- exporter.create_export_attribute(name, options)
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 create_export_describer(name, options)
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
- define_describer_method(kind: options[:kind], name: name)
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 create_export_attribute(name, options)
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
- private
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
- @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
- 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
- def new_exporting(describer:)
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)
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.5.0.dev4'
2
+ VERSION = '0.5.0.dev6'
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.dev4
4
+ version: 0.5.0.dev6
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource