Method: Chewy.strategy
- Defined in:
- lib/chewy.rb
.strategy(name = nil, &block) ⇒ Object
Strategies are designed to allow nesting, so it is possible to redefine it for nested contexts.
Chewy.strategy(:atomic) do city1.do_update! Chewy.strategy(:urgent) do city2.do_update! city3.do_update! # there will be 2 update index requests for city2 and city3 end city4..do_update! # city1 and city4 will be grouped in one index update request end
It is possible to nest strategies without blocks:
Chewy.strategy(:urgent) city1.do_update! # index updated Chewy.strategy(:bypass) city2.do_update! # update bypassed Chewy.strategy.pop city3.do_update! # index updated again
151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/chewy.rb', line 151 def strategy(name = nil, &block) Chewy.current[:chewy_strategy] ||= Chewy::Strategy.new if name if block Chewy.current[:chewy_strategy].wrap name, &block else Chewy.current[:chewy_strategy].push name end else Chewy.current[:chewy_strategy] end end |