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.4
1
+ 0.1.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{elastic_searchable}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Sonnek"]
@@ -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, callback_options
17
- after_commit_on_update :update_index_on_update_backgrounded, callback_options
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
@@ -9,7 +9,7 @@ module ElasticSearchable
9
9
  end
10
10
 
11
11
  self.find_each do |record|
12
- record.run_callbacks :after_commit_on_update
12
+ record.index_in_elastic_search if record.should_index?
13
13
  end
14
14
  self.refresh_index
15
15
  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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Sonnek