Class: Chewy::Strategy
- Inherits:
-
Object
show all
- Defined in:
- lib/chewy/strategy.rb,
lib/chewy/strategy/base.rb,
lib/chewy/strategy/atomic.rb,
lib/chewy/strategy/bypass.rb,
lib/chewy/strategy/resque.rb,
lib/chewy/strategy/urgent.rb,
lib/chewy/strategy/sidekiq.rb
Overview
This class represents strategies stack with ‘:base` Strategy on top of it. This causes raising exceptions on every index update attempt, so other strategy must be choosen.
User.first.save
Chewy.strategy(:atomic) do
User.last.save end
Defined Under Namespace
Classes: Atomic, Base, Bypass, Resque, Sidekiq, Urgent
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Strategy.
31
32
33
|
# File 'lib/chewy/strategy.rb', line 31
def initialize
@stack = [resolve(Chewy.root_strategy).new]
end
|
Instance Method Details
35
36
37
|
# File 'lib/chewy/strategy.rb', line 35
def current
@stack.last
end
|
45
46
47
48
49
50
|
# File 'lib/chewy/strategy.rb', line 45
def pop
raise "Can't pop root strategy" if @stack.one?
debug "[#{@stack.size}] -> #{current.name}"
result = @stack.pop.tap(&:leave)
result
end
|
#push(name) ⇒ Object
39
40
41
42
43
|
# File 'lib/chewy/strategy.rb', line 39
def push name
result = @stack.push resolve(name).new
debug "[#{@stack.size}] <- #{current.name}"
result
end
|
#wrap(name) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/chewy/strategy.rb', line 52
def wrap name
push name
yield
ensure
pop
end
|