Sha256: 0931f9fed8d932c1231261a86384c3b8d505fb2a1c2dd3d727af1f6a6384873c

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

module Grumlin
  class Steppable
    extend Forwardable

    START_STEPS = Grumlin.definitions.dig(:steps, :start).map(&:to_sym).freeze
    REGULAR_STEPS = Grumlin.definitions.dig(:steps, :regular).map(&:to_sym).freeze
    CONFIGURATION_STEPS = Grumlin.definitions.dig(:steps, :configuration).map(&:to_sym).freeze

    ALL_STEPS = START_STEPS + CONFIGURATION_STEPS + REGULAR_STEPS

    def initialize
      return if respond_to?(:shortcuts)

      raise RuntimerError,
            "steppable must not be initialized directly, use Grumlin::Shortcuts::Storage#g or #__ instead"
    end

    ALL_STEPS.each do |step|
      define_method step do |*args, **params|
        shortcuts.action_class.new(step, args: args, params: params, previous_step: self)
      end
    end

    def step(name, *args, **params)
      shortcuts.action_class.new(name, args: args, params: params, previous_step: self)
    end

    def_delegator :shortcuts, :__
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
grumlin-0.20.1 lib/grumlin/steppable.rb
grumlin-0.20.0 lib/grumlin/steppable.rb