Class: Workflow::Callbacks::Callback
- Inherits:
-
Object
- Object
- Workflow::Callbacks::Callback
- Includes:
- Comparable
- Defined in:
- lib/workflow/callbacks/callback.rb
Overview
Receives an expression and generates a lambda that can be called against an object, for use in callback logic.
Adapted from ActiveSupport::Callbacks https://github.com/rails/rails/blob/bca2e69b785fa3cdbe148b0d2dd5d3b58f6daf53/activesupport/lib/active_support/callbacks.rb#L296
Instance Attribute Summary collapse
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
Class Method Summary collapse
Instance Method Summary collapse
- #call(target) ⇒ Object
-
#initialize(expression, inverted = false) ⇒ Callback
constructor
A new instance of Callback.
Constructor Details
#initialize(expression, inverted = false) ⇒ Callback
Returns a new instance of Callback.
13 14 15 16 17 18 19 |
# File 'lib/workflow/callbacks/callback.rb', line 13 def initialize(expression, inverted=false) @expression = expression @callback = make_lambda(expression) if inverted @callback = invert_lambda(@callback) end end |
Instance Attribute Details
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
12 13 14 |
# File 'lib/workflow/callbacks/callback.rb', line 12 def callback @callback end |
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
12 13 14 |
# File 'lib/workflow/callbacks/callback.rb', line 12 def expression @expression end |
Class Method Details
.build_inverse(expression) ⇒ Object
25 26 27 |
# File 'lib/workflow/callbacks/callback.rb', line 25 def self.build_inverse(expression) new expression, true end |
Instance Method Details
#call(target) ⇒ Object
21 22 23 |
# File 'lib/workflow/callbacks/callback.rb', line 21 def call(target) callback.call(target, ->{}) end |