class Startback::Operation
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
Attributes
world[RW]
Public Instance Methods
bind(world)
click to toggle source
# File lib/startback/operation.rb, line 39 def bind(world) return self unless world self.world = world self end
method_missing(name, *args, &bl)
click to toggle source
Calls superclass method
# File lib/startback/operation.rb, line 45 def method_missing(name, *args, &bl) return super unless args.empty? and bl.nil? return super unless world world.fetch(name){ super } end
respond_to?(name, *args)
click to toggle source
Calls superclass method
# File lib/startback/operation.rb, line 51 def respond_to?(name, *args) super || (world && world.has_key?(name)) end
with_context(ctx = nil) { |: yield(world.context)| ... }
click to toggle source
# File lib/startback/operation.rb, line 55 def with_context(ctx = nil) old_world = self.world self.world = self.world.merge(context: ctx || old_world.context.dup) result = ctx ? yield : yield(self.world.context) self.world = old_world result end
Protected Instance Methods
operation_world(op)
click to toggle source
# File lib/startback/operation.rb, line 65 def operation_world(op) self.world end