Sha256: 101ab322738e56f7b6591f3e9a332b61f4afbddc009476390adc4da358ea3376

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Grumlin
  class Steppable
    extend Forwardable

    attr_reader :session_id

    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(pool: Grumlin.default_pool, session_id: nil)
      @pool = pool
      @session_id = session_id

      return if respond_to?(:shortcuts)

      raise "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, session_id: @session_id)
      end
    end

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

    def_delegator :shortcuts, :__
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
grumlin-0.22.4 lib/grumlin/steppable.rb
grumlin-0.22.3 lib/grumlin/steppable.rb
grumlin-0.22.2 lib/grumlin/steppable.rb
grumlin-0.22.1 lib/grumlin/steppable.rb
grumlin-0.22.0 lib/grumlin/steppable.rb
grumlin-0.21.1 lib/grumlin/steppable.rb