Class: Workflow::Event::Conditions Private

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow/event.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Maintains a list of callback procs which are evaluted to determine if the transition on which they were defined is valid for an object in its current state. Borrowed from ActiveSupport::Callbacks See original source here

Instance Method Summary collapse

Constructor Details

#initialize(**options, &block) ⇒ Conditions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Conditions.



125
126
127
128
129
130
# File 'lib/workflow/event.rb', line 125

def initialize(**options, &block)
  @if      = Array(options[:if])
  @unless  = Array(options[:unless])
  @if << block if block_given?
  @conditions_lambdas = conditions_lambdas
end

Instance Method Details

#apply?(target) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


136
137
138
# File 'lib/workflow/event.rb', line 136

def apply?(target)
  @conditions_lambdas.all? { |l| l.call(target) }
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/workflow/event.rb', line 132

def inspect
  "if: #{@if}, unless: #{@unless}"
end