Class: Chewy::Strategy
- Inherits:
-
Object
- Object
- Chewy::Strategy
- Defined in:
- lib/chewy/strategy.rb,
lib/chewy/strategy/base.rb,
lib/chewy/strategy/atomic.rb,
lib/chewy/strategy/bypass.rb,
lib/chewy/strategy/urgent.rb,
lib/chewy/strategy/sidekiq.rb,
lib/chewy/strategy/active_job.rb,
lib/chewy/strategy/lazy_sidekiq.rb,
lib/chewy/strategy/delayed_sidekiq.rb,
lib/chewy/strategy/atomic_no_refresh.rb,
lib/chewy/strategy/delayed_sidekiq/worker.rb,
lib/chewy/strategy/delayed_sidekiq/scheduler.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 # Raises UndefinedUpdateStrategy exception
Chewy.strategy(:atomic) do
User.last.save # Save user according to the :atomic
strategy rules
end
Defined Under Namespace
Classes: ActiveJob, Atomic, AtomicNoRefresh, Base, Bypass, DelayedSidekiq, LazySidekiq, Sidekiq, Urgent
Instance Method Summary collapse
- #current ⇒ Object
-
#initialize ⇒ Strategy
constructor
A new instance of Strategy.
- #pop ⇒ Object
- #push(name) ⇒ Object
- #wrap(name) ⇒ Object
Constructor Details
Instance Method Details
#current ⇒ Object
40 41 42 |
# File 'lib/chewy/strategy.rb', line 40 def current @stack.last end |
#pop ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/chewy/strategy.rb', line 50 def pop raise "Can't pop root strategy" if @stack.one? result = @stack.pop.tap(&:leave) debug "[#{@stack.size}] -> #{result.name}, now #{current.name}" if @stack.size > 1 result end |
#push(name) ⇒ Object
44 45 46 47 48 |
# File 'lib/chewy/strategy.rb', line 44 def push(name) result = @stack.push resolve(name).new debug "[#{@stack.size - 1}] <- #{current.name}" if @stack.size > 2 result end |
#wrap(name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/chewy/strategy.rb', line 58 def wrap(name) stack = push(name) yield ensure pop if stack end |