activekit 0.5.0 → 0.5.1
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/bedrock/bedrocker.rb +2 -2
- data/lib/active_kit/search/searcher.rb +47 -22
- data/lib/active_kit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8622adf4eedf9b9fa1b4f31b70e8f9fb588560248d25a2f2dd571bd6a49472e9
|
4
|
+
data.tar.gz: cc1adb9159fffe8865e7c907a684c22d991cccd5c3ff2e773e436c779eb8cb76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8be02259a5fa52ea71fed586d7843f0e42c9045f818ded4476746ab5e483ec4183132164eb112268dcf1a16d44b783b3a549071ad91acc6c500e45c1644a592e
|
7
|
+
data.tar.gz: 224b675066b9134bc3ca74f225e602fcc66eabeda580f07f7affa2538b22e0fc781ede082cccdea9bfa4b97d0088011d86949e5e80d7525dd02622722869d3fc
|
@@ -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
|
-
|
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
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/active_kit/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- plainsource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|