Class: ActionFlow::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/action_flow/flow.rb,
lib/action_flow/flow/state.rb,
lib/action_flow/flow/controller.rb

Defined Under Namespace

Classes: Controller, State

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expressions) ⇒ Flow

Returns a new instance of Flow.



6
7
8
9
10
# File 'lib/action_flow/flow.rb', line 6

def initialize(expressions)
  @expressions = expressions
  @mutexes     = []
  @terminators = []
end

Instance Attribute Details

#mutexesObject

Returns the value of attribute mutexes.



4
5
6
# File 'lib/action_flow/flow.rb', line 4

def mutexes
  @mutexes
end

#terminatorsObject

Returns the value of attribute terminators.



4
5
6
# File 'lib/action_flow/flow.rb', line 4

def terminators
  @terminators
end

Instance Method Details

#===(context) ⇒ Object



31
32
33
# File 'lib/action_flow/flow.rb', line 31

def ===(context)
  @expressions.any? { |expr| match_expression?(expr, context) }
end

#action_at(index, env, params = {}) ⇒ Object



46
47
48
49
50
# 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) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/action_flow/flow.rb', line 16

def begins_with?(context)
  match_at?(0, context)
end

#lengthObject



12
13
14
# File 'lib/action_flow/flow.rb', line 12

def length
  @expressions.length
end

#match_at?(index, context, exact = false) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# 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) ⇒ Object



39
40
41
42
43
44
# 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) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# 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) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/action_flow/flow.rb', line 35

def terminates_on?(context)
  @terminators.any? { |expr| expr === context }
end