Class: Forminator::Flow

Inherits:
Object
  • Object
show all
Defined in:
lib/forminator/flow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(steps:) ⇒ Flow

Returns a new instance of Flow.



5
6
7
8
# File 'lib/forminator/flow.rb', line 5

def initialize(steps:)
  @steps = steps
  @current_step = initial_step
end

Instance Attribute Details

#current_stepObject (readonly)

Returns the value of attribute current_step.



3
4
5
# File 'lib/forminator/flow.rb', line 3

def current_step
  @current_step
end

#stepsObject (readonly)

Returns the value of attribute steps.



3
4
5
# File 'lib/forminator/flow.rb', line 3

def steps
  @steps
end

Instance Method Details

#add(step:) ⇒ Object



23
24
25
26
# File 'lib/forminator/flow.rb', line 23

def add(step:)
  raise Forminator::InvalidStep unless step.ancestors.include?(Forminator::Step)
  steps << step
end

#initial_stepObject



19
20
21
# File 'lib/forminator/flow.rb', line 19

def initial_step
  steps.first
end

#next_stepObject



10
11
12
# File 'lib/forminator/flow.rb', line 10

def next_step
  steps[steps.index(current_step) + 1]
end

#previous_stepObject



14
15
16
17
# File 'lib/forminator/flow.rb', line 14

def previous_step
  # TODO: there is no previous step??
  steps[steps.index(current_step) - 1]
end

#remove(step:) ⇒ Object



28
29
30
# File 'lib/forminator/flow.rb', line 28

def remove(step:)
  steps.delete(step)
end