activekit 0.5.0.dev5 → 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: '068662b0f0144c92e082fc2a3e5002695a090dc1a4547a79889a945e739b7593'
4
- data.tar.gz: a782fef4b69dfd9df1869c78e5826c8699adaf5339ca066ca48531ba391f66c5
3
+ metadata.gz: 4be51587fe2bc2ef391a14a432ab155a50489acd765845dd88212c56bfbd5328
4
+ data.tar.gz: 9839b9510d9610ca93573dda2e4e83b05b1cd1aa2c9902ff96f2dc83d2385af4
5
5
  SHA512:
6
- metadata.gz: c0b3d0c3bd09b6d4de855c802ca0e4e47485a3fa727331088ff9b0ed3f21bf701485f6f15addd0d4b16cabad7442cb5d8d3f256e5b9d524ea36a0c0b2e58ce70
7
- data.tar.gz: 6d74e3e1775bd54f86022f40815593f3e0c60d6fdbb3fed1d14054c633f4af2b1456d1ad03018aaf2b9698fd0aadc123c3884edcd996af3f1ad7405238dcc5aa
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,23 +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
- describer = find_describer_by(describer_name: name)
17
- define_describer_method(describer)
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
18
23
  end
19
24
  end
20
25
 
21
- def create_export_attribute(name, options)
22
- create_export_describer(:to_csv, kind: :csv, database: -> { ActiveRecord::Base.connection_db_config.database.to_sym }) unless @describers.present?
23
-
26
+ def create_attribute(name, options)
24
27
  options.deep_symbolize_keys!
25
28
 
29
+ create_describer(:to_csv, kind: :csv, database: -> { ActiveRecord::Base.connection_db_config.database.to_sym }) unless @describers.present?
30
+
26
31
  describer_names = Array(options.delete(:describers))
27
32
  describer_names = @describers.keys if describer_names.blank?
28
33
 
@@ -33,40 +38,32 @@ module ActiveKit
33
38
  end
34
39
  end
35
40
 
36
- private
37
-
38
- def define_describer_method(describer)
41
+ def describer_method(describer)
39
42
  case describer.kind
40
43
  when :csv
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
60
- 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) }
61
60
  end
62
61
  end
63
62
  end
64
63
  end
65
64
  end
66
65
 
67
- def new_exporting(describer:)
68
- Exporting.new(describer: describer)
69
- end
66
+ private
70
67
 
71
68
  def find_describer_by(describer_name:)
72
69
  describer_options = @describers.dig(describer_name)
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.5.0.dev5'
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.dev5
4
+ version: 0.5.0.dev6
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource