class ActionFlow::Flow

Attributes

mutexes[RW]
terminators[RW]

Public Class Methods

new(expressions) click to toggle source
# File lib/action_flow/flow.rb, line 6
def initialize(expressions)
  @expressions = expressions
  @mutexes     = []
  @terminators = []
end

Public Instance Methods

===(context) click to toggle source
# File lib/action_flow/flow.rb, line 31
def ===(context)
  @expressions.any? { |expr| match_expression?(expr, context) }
end
action_at(index, env, params = {}) click to toggle source
# File lib/action_flow/flow.rb, line 46
def action_at(index, env, params = {})
  return nil unless expression = @expressions[index]
  return ActionFlow.flows[expression].action_at(0, env, params) if Symbol === expression
  expression.to_params(env).merge(params)
end
begins_with?(context) click to toggle source
# File lib/action_flow/flow.rb, line 16
def begins_with?(context)
  match_at?(0, context)
end
length() click to toggle source
# File lib/action_flow/flow.rb, line 12
def length
  @expressions.length
end
match_at?(index, context, exact = false) click to toggle source
# File lib/action_flow/flow.rb, line 20
def match_at?(index, context, exact = false)
  return false unless expression = @expressions[index]
  match_expression?(expression, context, exact)
end
match_distance(index, context) click to toggle source
# File lib/action_flow/flow.rb, line 39
def match_distance(index, context)
  return 1000 unless expression = @expressions[index]
  return 0 if expression === context
  return 1 if Symbol === expression and ActionFlow.flows[expression] === context
  1000
end
match_expression?(expression, context, exact = false) click to toggle source
# File lib/action_flow/flow.rb, line 25
def match_expression?(expression, context, exact = false)
  return expression.any? { |atom| match_expression?(atom, context, exact) } if Array === expression
  return ActionFlow.flows[expression] === context if Symbol === expression and not exact
  expression === context
end
terminates_on?(context) click to toggle source
# File lib/action_flow/flow.rb, line 35
def terminates_on?(context)
  @terminators.any? { |expr| expr === context }
end