Sha256: 23e228ebc88f20837f1a0dcd4b72beef4b7b9c68a0be8096b2f37d76cdd410b6

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

require "wisper"
require "active_support/configurable"

module Action
  class Base
    include ActiveSupport::Configurable
    include Wisper::Publisher

    def configure
      yield config if block_given?
      self
    end

    # default implementation
    # plan arg is a planning DSL
    def plan plan
      plan.myself if respond_to?(:run)
    end

    # plan arg is an Action::Plan instance
    def expand_into plan:
      plan PlanningDSL.new(plan: plan, action: self)
    end

    class PlanningDSL
      def initialize plan:, action:
        @plan = plan
        @action = action
      end

      def myself
        @plan.schedule_action(@action.class, @action.config)
      end

      def action action_class, &block
        @plan.plan_action(action_class, &block)
      end
    end

    protected

    def todo= total
    end

    def done= count
    end
  end

  class Error < RuntimeError ; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
action-plan-0.1.0 lib/action/base.rb