Class: Grumlin::Steps

Inherits:
Object
  • Object
show all
Defined in:
lib/grumlin/steps.rb

Constant Summary collapse

CONFIGURATION_STEPS =
Grumlin::Step::CONFIGURATION_STEPS
ALL_STEPS =
Grumlin::Step::ALL_STEPS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shortcuts, configuration_steps: [], steps: []) ⇒ Steps

Returns a new instance of Steps.



20
21
22
23
24
# File 'lib/grumlin/steps.rb', line 20

def initialize(shortcuts, configuration_steps: [], steps: [])
  @shortcuts = shortcuts
  @configuration_steps = configuration_steps
  @steps = steps
end

Instance Attribute Details

#configuration_stepsObject (readonly)

Returns the value of attribute configuration_steps.



18
19
20
# File 'lib/grumlin/steps.rb', line 18

def configuration_steps
  @configuration_steps
end

#shortcutsObject (readonly)

Returns the value of attribute shortcuts.



18
19
20
# File 'lib/grumlin/steps.rb', line 18

def shortcuts
  @shortcuts
end

#stepsObject (readonly)

Returns the value of attribute steps.



18
19
20
# File 'lib/grumlin/steps.rb', line 18

def steps
  @steps
end

Class Method Details

.from(step) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
# File 'lib/grumlin/steps.rb', line 7

def self.from(step)
  raise ArgumentError, "expected: #{Grumlin::Step}, given: #{step.class}" unless step.is_a?(Grumlin::Step)

  new(step.shortcuts).tap do |chain|
    until step.nil? || step.is_a?(Grumlin::TraversalStart)
      chain.add(step.name, args: step.args, params: step.params, to: :begin)
      step = step.previous_step
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
44
45
46
# File 'lib/grumlin/steps.rb', line 41

def ==(other)
  self.class == other.class &&
    @shortcuts == other.shortcuts &&
    @configuration_steps == other.configuration_steps &&
    @steps == other.steps
end

#add(name, args: [], params: {}, to: :end) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/grumlin/steps.rb', line 26

def add(name, args: [], params: {}, to: :end)
  return add_configuration_step(name, args:, params:, to:) if CONFIGURATION_STEPS.include?(name) || name.to_sym == :tx

  Grumlin::StepData.new(name, args: cast_arguments(args), params:).tap do |step|
    next @steps << step if to == :end
    next @steps.unshift(step) if to == :begin

    raise ArgumentError, "'to:' must be either :begin or :end, given: '#{to}'"
  end
end

#uses_shortcuts?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/grumlin/steps.rb', line 37

def uses_shortcuts?
  shortcuts?(@configuration_steps) || shortcuts?(@steps)
end