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 +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 +4 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba3aca1371dc2faabb495460be4001b827591a485579b33d1e1c880a88df88ee
|
4
|
+
data.tar.gz: 63bad99e0d6b416b6a2b9b565134068fd02a1c943b05439aac5d0ebc17357124
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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-
|
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:
|
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:
|
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
|