class Chewy::Index::Observe::Callback

Public Class Methods

new(executable, filters = {}) click to toggle source
# File lib/chewy/index/observe/callback.rb, line 5
def initialize(executable, filters = {})
  @executable = executable
  @if_filter = filters[:if]
  @unless_filter = filters[:unless]
end

Public Instance Methods

call(context) click to toggle source
# File lib/chewy/index/observe/callback.rb, line 11
def call(context)
  return if !@if_filter.nil? && !eval_filter(@if_filter, context)
  return if !@unless_filter.nil? && eval_filter(@unless_filter, context)

  eval_proc(@executable, context)
end

Private Instance Methods

eval_filter(filter, context) click to toggle source
# File lib/chewy/index/observe/callback.rb, line 20
def eval_filter(filter, context)
  case filter
  when Symbol then context.send(filter)
  when Proc then eval_proc(filter, context)
  else filter
  end
end
eval_proc(executable, context) click to toggle source
# File lib/chewy/index/observe/callback.rb, line 28
def eval_proc(executable, context)
  executable.arity.zero? ? context.instance_exec(&executable) : executable.call(context)
end