Class: StepMachine::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/step_machine/step.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Step

Returns a new instance of Step.



8
9
10
# File 'lib/step_machine/step.rb', line 8

def initialize(name)
  self.name = name
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



5
6
7
# File 'lib/step_machine/step.rb', line 5

def block
  @block
end

#condition_blockObject (readonly)

Returns the value of attribute condition_block.



6
7
8
# File 'lib/step_machine/step.rb', line 6

def condition_block
  @condition_block
end

#exceptionObject

Returns the value of attribute exception.



5
6
7
# File 'lib/step_machine/step.rb', line 5

def exception
  @exception
end

#groupObject

Returns the value of attribute group.



5
6
7
# File 'lib/step_machine/step.rb', line 5

def group
  @group
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/step_machine/step.rb', line 5

def name
  @name
end

#next_step(&block) ⇒ Object

Returns the value of attribute next_step.



5
6
7
# File 'lib/step_machine/step.rb', line 5

def next_step
  @next_step
end

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/step_machine/step.rb', line 6

def result
  @result
end

#validationObject (readonly)

Returns the value of attribute validation.



6
7
8
# File 'lib/step_machine/step.rb', line 6

def validation
  @validation
end

Instance Method Details

#condition(&block) ⇒ Object



33
34
35
36
# File 'lib/step_machine/step.rb', line 33

def condition(&block)
  @condition_block = block if block
  self
end

#errors(init_error = nil) ⇒ Object



17
18
19
20
21
# File 'lib/step_machine/step.rb', line 17

def errors(init_error = nil)
  @errors = init_error if (!init_error.nil? and init_error.class != @errors.class)
  @errors = [] if (init_error.nil? && @errors.nil?)
  @errors
end

#nextObject



38
39
40
41
# File 'lib/step_machine/step.rb', line 38

def next
  return next_step.call(self) if next_step.is_a?(Proc)
  next_step
end

#performObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/step_machine/step.rb', line 43

def perform
  return true unless condition_satisfied
  @performed = true
  @result = block.call(self)
  valid = valid?
  @success.call(self) if @success && valid
  valid
rescue => e
  @exception = e
  false
end

#performed?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/step_machine/step.rb', line 55

def performed?
  !!@performed
end

#success(&block) ⇒ Object



23
24
25
26
# File 'lib/step_machine/step.rb', line 23

def success(&block)
  @success = block
  self
end

#validate(value = nil, &block) ⇒ Object



12
13
14
15
# File 'lib/step_machine/step.rb', line 12

def validate(value = nil, &block)     
  @validation = block || value
  self
end