Class: Grumlin::Steps
- Inherits:
-
Object
- Object
- Grumlin::Steps
- Defined in:
- lib/grumlin/steps.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#configuration_steps ⇒ Object
readonly
Returns the value of attribute configuration_steps.
-
#shortcuts ⇒ Object
readonly
Returns the value of attribute shortcuts.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add(name, args: [], params: {}, to: :end) ⇒ Object
-
#initialize(shortcuts, configuration_steps: [], steps: []) ⇒ Steps
constructor
A new instance of Steps.
- #uses_shortcuts? ⇒ Boolean
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_steps ⇒ Object (readonly)
Returns the value of attribute configuration_steps.
18 19 20 |
# File 'lib/grumlin/steps.rb', line 18 def configuration_steps @configuration_steps end |
#shortcuts ⇒ Object (readonly)
Returns the value of attribute shortcuts.
18 19 20 |
# File 'lib/grumlin/steps.rb', line 18 def shortcuts @shortcuts end |
#steps ⇒ Object (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
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
37 38 39 |
# File 'lib/grumlin/steps.rb', line 37 def uses_shortcuts? shortcuts?(@configuration_steps) || shortcuts?(@steps) end |