Sha256: 82e258e0867f1b3c5a448d80b69fb2f0569fdb035a99d11f7d76309ad4f7f254

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require "ruby2_keywords"

module Neo
  module DCI
    class Context
      class << self
        private :new

        def callbacks(*args)
          @callbacks ||= []
          @callbacks = args unless args.empty?
          @callbacks
        end

        ruby2_keywords def call(*args, &block)
          context = new(*args)
          context.callback = result_class.new(*callbacks, &block)
          context.call
          raise NoCallbackCalled, callbacks unless context.callback.called?
        rescue NotImplementedError
          raise
        end

        def result_class(klass = :reader)
          @result_class = klass unless klass == :reader
          defined?(@result_class) ? @result_class : ContextResult
        end
      end

      attr_accessor :callback

      def call
        raise NotImplementedError
      end

      class NoCallbackCalled < StandardError
        def initialize(callbacks)
          super("No callback called. Available callbacks: #{callbacks.join(", ")}")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neo-dci-0.6.0 lib/neo/dci/context.rb