Sha256: bcab3b32c1ee6f1b79fd8ddc5c866f00273a48d65e9fd9b1a41361cb43ac7e94

Contents?: true

Size: 1.59 KB

Versions: 9

Compression:

Stored size: 1.59 KB

Contents

module Startback
  #
  # High-level Operation abstraction, that is a piece of code that executes
  # on demand and (generally) changes the state of the software system.
  #
  # An operation is basically an object that respond to `call`, but that
  # executes within a given world (see `bind`). It also has before and
  # after hooks that allows specifying what needs to be done before invoking
  # call and after having invoked it. All this protocol is actually under
  # the responsibility of an `OperationRunner`. Operations should not be
  # called manually by third-party code.
  #
  # Example:
  #
  #     class SayHello < Startback::Operation
  #
  #       before_call do
  #         # e.g. check_some_permissions
  #       end
  #
  #       def call
  #         puts "Hello"
  #       end
  #
  #       after_call do
  #         # e.g. log and/or emit something on a bus
  #       end
  #
  #     end
  #
  class Operation
    include Errors
    include Support::OperationRunner
    include Support::Hooks.new(:call)

    attr_accessor :world
    protected :world=

    def bind(world)
      return self unless world
      self.world = world
      self
    end

    def method_missing(name, *args, &bl)
      return super unless args.empty? and bl.nil?
      return super unless world
      world.fetch(name){ super }
    end

    def respond_to?(name, *args)
      super || (world && world.has_key?(name))
    end

  protected

    def operation_world(op)
      self.world
    end

  end # class Operation
end # module Startback
require_relative 'operation/error_operation'
require_relative 'operation/multi_operation'

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
startback-0.7.1 lib/startback/operation.rb
startback-0.7.0 lib/startback/operation.rb
startback-0.6.0 lib/startback/operation.rb
startback-0.5.5 lib/startback/operation.rb
startback-0.5.4 lib/startback/operation.rb
startback-0.5.3 lib/startback/operation.rb
startback-0.5.2 lib/startback/operation.rb
startback-0.5.1 lib/startback/operation.rb
startback-0.5.0 lib/startback/operation.rb