Class: RubyExt::Callbacks::BeforeCallback

Inherits:
AbstractCallback show all
Defined in:
lib/ruby_ext/more/callbacks.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractCallback

#conditions, #executor

Instance Method Summary collapse

Methods inherited from AbstractCallback

#run?

Instance Attribute Details

#terminatorObject

Returns the value of attribute terminator.



64
65
66
# File 'lib/ruby_ext/more/callbacks.rb', line 64

def terminator
  @terminator
end

Instance Method Details

#build_block(target, method, data, &block) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/ruby_ext/more/callbacks.rb', line 66

def build_block target, method, data, &block
  -> do
    if run? target, method, data
      block.call if run target, data
    else
      block.call
    end
  end
end

#run(target, data) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ruby_ext/more/callbacks.rb', line 76

def run target, data
  callback_result = if executor.is_a? Symbol
    target.send executor
  elsif executor.is_a? Proc
    executor.call target
  else
    must.be_never_called
  end

  !terminate?(target, callback_result)
end