activekit 0.5.0 → 0.6.0

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: 71b9eb7bd5fc27d2794cd15b8ec08a68e9baae06e37e072188260ddbaaa25473
4
- data.tar.gz: 33f906a96b417c86b8048a2f663dbac5d4a6b0595f9cea23b6a0db92f98982cb
3
+ metadata.gz: ba3aca1371dc2faabb495460be4001b827591a485579b33d1e1c880a88df88ee
4
+ data.tar.gz: 63bad99e0d6b416b6a2b9b565134068fd02a1c943b05439aac5d0ebc17357124
5
5
  SHA512:
6
- metadata.gz: 5172f9cb6b0aa0623a9e6f9a0263de7a5fadc016a25c6b92514f9916fca13653f8326479f4bc7fa8c54314c77c8d9d75435034b3c0e1e40054f7f002bf969d90
7
- data.tar.gz: 65cb7a16747fb2281042dced7e1781bf0709437c470e8621b7ee232b6b205ab1ad021d8b1287a147abba85ddb96fe4f020e1ebb455b00a532d45488fbdf6d47f
6
+ metadata.gz: af8a6fc28a2b4b38a49f690a11384c0199837e6fb983475690bd44d4f69fbd3a063ba6da8f030e464903bea734f71af4888baf45eb628fc799e031b060f6b381
7
+ data.tar.gz: d241982535485df4b8a253e5e3a46087839339717350816b97ca4226423175a36489409106f453a95ebf1d8b8e66093b623818d22028a3dbf68d23c07249e462
@@ -50,10 +50,10 @@ module ActiveKit
50
50
 
51
51
  def for(describer_name)
52
52
  describer_name = @describers.keys[0] if describer_name.nil?
53
- raise "Could not find any describer name in #{@current_class.name}." if describer_name.blank?
53
+ raise "Could not find any describer name in '#{@current_class.name}'." if describer_name.blank?
54
54
 
55
55
  describer_name = describer_name.to_sym
56
- raise "Could not find describer '#{describer_name}' in #{@current_class.name}." unless @describers.dig(describer_name)
56
+ raise "Could not find describer '#{describer_name}' in '#{@current_class.name}'." unless @describers.dig(describer_name)
57
57
  componenting = @describers.dig(describer_name, :componenting)
58
58
  return componenting if componenting
59
59
 
@@ -6,7 +6,7 @@ module ActiveKit
6
6
 
7
7
  depends_on = options.delete(:depends_on) || {}
8
8
  describer_names.each do |describer_name|
9
- set_reload_callbacks(depends_on, describer_name)
9
+ set_callbacks(describer_name, depends_on)
10
10
  self.for(describer_name).add_attribute(name: name, options: options.deep_dup)
11
11
  end
12
12
  end
@@ -18,33 +18,58 @@ module ActiveKit
18
18
 
19
19
  private
20
20
 
21
- # Set callbacks for current class and depending classes.
22
- def set_reload_callbacks(depends_on, describer_name)
23
- @current_class.class_eval do
24
- unless searcher.for(describer_name).attributes_present?
25
- after_commit do
26
- self.class.searcher.for(describer_name).reload(record: self)
27
- logger.info "ActiveKit::Search | Indexing from #{self.class.name}: Done."
28
- end
29
- end
21
+ # Set callbacks for depending classes and then current class.
22
+ def set_callbacks(describer_name, depends_on)
23
+ depends_on.each do |depends_on_association, depends_on_inverse|
24
+ klass = @current_class.reflect_on_all_associations.map { |assoc| [assoc.name, assoc.klass.name] }.to_h[depends_on_association]
25
+
26
+ next if klass.constantize.private_method_defined?(after_commit_depends_callback_method_name(describer_name))
27
+ klass.constantize.class_eval <<-CODE, __FILE__, __LINE__ + 1
28
+ after_commit :#{after_commit_depends_callback_method_name(describer_name)}
29
+
30
+ private
30
31
 
31
- unless depends_on.empty?
32
- depends_on.each do |depends_on_association, depends_on_inverse|
33
- klass = self.reflect_on_all_associations.map { |assoc| [assoc.name, assoc.klass.name] }.to_h[depends_on_association]
34
- klass.constantize.class_eval do
35
- after_commit do
36
- inverse_assoc = self.public_send(depends_on_inverse)
37
- if inverse_assoc.respond_to?(:each)
38
- inverse_assoc.each { |instance| instance.class.searcher.for(describer_name).reload(record: instance) }
39
- else
40
- inverse_assoc.class.searcher.for(describer_name).reload(record: inverse_assoc)
32
+ def #{after_commit_depends_callback_method_name(describer_name)}
33
+ inverse_assoc = self.public_send("#{depends_on_inverse}")
34
+ if inverse_assoc.respond_to?(:each)
35
+ inverse_assoc.each do |instance|
36
+ if instance.class.name == "#{@current_class.name}"
37
+ instance.class.searcher.for("#{describer_name}").reload(record: instance)
41
38
  end
42
- logger.info "ActiveKit::Search | Indexing from #{self.class.name}: Done."
39
+ end
40
+ else
41
+ if inverse_assoc.class.name == "#{@current_class.name}"
42
+ inverse_assoc.class.searcher.for("#{describer_name}").reload(record: inverse_assoc)
43
43
  end
44
44
  end
45
+ logger.info "ActiveKit::Search | Indexing Done. (Class: " + self.class.name + " | Reloading: #{@current_class.name} | Describer: #{describer_name})"
45
46
  end
46
- end
47
+ CODE
47
48
  end
49
+
50
+ return if @current_class.private_method_defined?(after_commit_callback_method_name(describer_name))
51
+ @current_class.class_eval <<-CODE, __FILE__, __LINE__ + 1
52
+ after_commit :#{after_commit_callback_method_name(describer_name)}
53
+
54
+ private
55
+
56
+ def #{after_commit_callback_method_name(describer_name)}
57
+ self.class.searcher.for("#{describer_name}").reload(record: self)
58
+ logger.info "ActiveKit::Search | Indexing Done. (Class: " + self.class.name + " | Reloading: #{@current_class.name} | Describer: #{describer_name})"
59
+ end
60
+ CODE
61
+ end
62
+
63
+ def after_commit_callback_method_name(describer_name)
64
+ "#{callback_method_name(describer_name)}_callback"
65
+ end
66
+
67
+ def after_commit_depends_callback_method_name(describer_name)
68
+ "#{callback_method_name(describer_name)}_depends_callback"
69
+ end
70
+
71
+ def callback_method_name(describer_name)
72
+ "activekit_search_#{@current_class.model_name.singular}_#{describer_name}"
48
73
  end
49
74
  end
50
75
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveKit
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activekit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.1.3
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 6.1.3.1
19
+ version: 7.0.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 6.1.3
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 6.1.3.1
26
+ version: 7.0.0
33
27
  description: Add the essential kit for rails ActiveRecord models and be happy.
34
28
  email:
35
29
  - plainsource@timeboard.org