elastic_searchable 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/elastic_searchable.gemspec
CHANGED
@@ -50,6 +50,32 @@ module ElasticSearchable
|
|
50
50
|
self.run_callbacks("after_index_on_#{lifecycle}".to_sym) if lifecycle
|
51
51
|
self.run_callbacks(:after_index)
|
52
52
|
end
|
53
|
+
def should_index?
|
54
|
+
[self.class.elastic_options[:if]].flatten.compact.all? { |a| evaluate_method(a, *args) } &&
|
55
|
+
![self.class.elastic_options[:unless]].flatten.compact.any? { |a| evaluate_method(a, *args) }
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
#ripped from activesupport
|
60
|
+
def evaluate_method(method, *args, &block)
|
61
|
+
case method
|
62
|
+
when Symbol
|
63
|
+
object = args.shift
|
64
|
+
object.send(method, *args, &block)
|
65
|
+
when String
|
66
|
+
eval(method, args.first.instance_eval { binding })
|
67
|
+
when Proc, Method
|
68
|
+
method.call(*args, &block)
|
69
|
+
else
|
70
|
+
if method.respond_to?(kind)
|
71
|
+
method.send(kind, *args, &block)
|
72
|
+
else
|
73
|
+
raise ArgumentError,
|
74
|
+
"Callbacks must be a symbol denoting the method to call, a string to be evaluated, " +
|
75
|
+
"a block to be invoked, or an object responding to the callback method."
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
53
79
|
end
|
54
80
|
end
|
55
81
|
end
|
@@ -11,10 +11,9 @@ module ElasticSearchable
|
|
11
11
|
backgrounded :delete_id_from_index => {:queue => 'searchindex'}
|
12
12
|
end
|
13
13
|
|
14
|
-
callback_options = self.elastic_options.slice :if, :unless
|
15
14
|
define_callbacks :after_index_on_create, :after_index_on_update, :after_index
|
16
|
-
after_commit_on_create :update_index_on_create_backgrounded,
|
17
|
-
after_commit_on_update :update_index_on_update_backgrounded,
|
15
|
+
after_commit_on_create :update_index_on_create_backgrounded, :if => :should_index?
|
16
|
+
after_commit_on_update :update_index_on_update_backgrounded, :if => :should_index?
|
18
17
|
after_commit_on_destroy Proc.new {|o| o.class.delete_id_from_index_backgrounded(o.id) }
|
19
18
|
end
|
20
19
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic_searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Sonnek
|