Class: Transflow::FlowDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/transflow/flow_dsl.rb

Defined Under Namespace

Modules: Registry

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ FlowDSL



26
27
28
29
30
31
# File 'lib/transflow/flow_dsl.rb', line 26

def initialize(options, &block)
  @options = options
  @container = options.fetch(:container)
  @steps = {}
  instance_exec(&block)
end

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



22
23
24
# File 'lib/transflow/flow_dsl.rb', line 22

def container
  @container
end

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/transflow/flow_dsl.rb', line 20

def options
  @options
end

#stepsObject (readonly)

Returns the value of attribute steps.



24
25
26
# File 'lib/transflow/flow_dsl.rb', line 24

def steps
  @steps
end

Class Method Details

.[](op) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/transflow/flow_dsl.rb', line 12

def self.[](op)
  if op.respond_to?(:>>)
    op
  else
    Registry[op]
  end
end

Instance Method Details

#callObject



37
38
39
# File 'lib/transflow/flow_dsl.rb', line 37

def call
  Transaction.new(steps, operations.reduce(:>>))
end

#operationsObject



41
42
43
# File 'lib/transflow/flow_dsl.rb', line 41

def operations
  steps.values.reverse.map { |op| self.class[op] }
end

#step(*args, &block) ⇒ Object



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

def step(*args, &block)
  StepDSL.new(*args, container, steps, &block).call
end