Class: ActionFlow::DSL

Inherits:
BlankSlate show all
Includes:
Expression::Generator
Defined in:
lib/action_flow.rb

Instance Method Summary collapse

Methods included from Expression::Generator

#find, #method_missing

Methods inherited from BlankSlate

all_methods, include, new, remove_inherited_methods

Constructor Details

#initialize(flow_register, &block) ⇒ DSL

Returns a new instance of DSL.



28
29
30
31
# File 'lib/action_flow.rb', line 28

def initialize(flow_register, &block)
  @flow_register = flow_register
  instance_eval(&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActionFlow::Expression::Generator

Instance Method Details

#flow(name, *expressions) ⇒ Object



33
34
35
# File 'lib/action_flow.rb', line 33

def flow(name, *expressions)
  @flow_register.flows[name.to_sym] = Flow.new(expressions)
end

#mutex(*names) ⇒ Object



37
38
39
40
41
42
# File 'lib/action_flow.rb', line 37

def mutex(*names)
  names.each do |name|
    next unless flow = @flow_register.flows[name]
    flow.mutexes = names - [name]
  end
end

#terminate(*args) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/action_flow.rb', line 44

def terminate(*args)
  expression_options = args.pop

  unless expression_options.respond_to?(:[]) && expression = expression_options[:on]
    raise ArgumentError, 'Could not find :on => expression in terminate'
  end

  args.each do |arg|
    flow_name = arg.to_sym
    next unless @flow_register.flows[flow_name]
    @flow_register.flows[flow_name].terminators << expression
  end
end