Class: Startback::Operation
- Inherits:
-
Object
- Object
- Startback::Operation
- Includes:
- Errors, Support::OperationRunner
- Defined in:
- lib/startback/operation.rb,
lib/startback/operation/error_operation.rb,
lib/startback/operation/multi_operation.rb
Overview
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
Direct Known Subclasses
Defined Under Namespace
Classes: ErrorOperation, MultiOperation
Instance Attribute Summary collapse
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Instance Method Summary collapse
- #bind(world) ⇒ Object
- #method_missing(name, *args, &bl) ⇒ Object
- #respond_to?(name, *args) ⇒ Boolean
- #with_context(ctx = nil) ⇒ Object
Methods included from Support::OperationRunner
Methods included from Errors
bad_request_error!, conflict_error!, expectation_failed_error!, forbidden_error!, gone_error!, internal_server_error!, locked_error!, method_not_allowed_error!, not_acceptable_error!, not_found_error!, not_implemented_error!, precondition_failed_error!, precondition_required_error!, server_error!, unauthorized_error!, unsupported_media_type_error!, user_error!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &bl) ⇒ Object
45 46 47 48 49 |
# 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 |
Instance Attribute Details
#world ⇒ Object
Returns the value of attribute world.
36 37 38 |
# File 'lib/startback/operation.rb', line 36 def world @world end |
Instance Method Details
#bind(world) ⇒ Object
39 40 41 42 43 |
# File 'lib/startback/operation.rb', line 39 def bind(world) return self unless world self.world = world self end |
#respond_to?(name, *args) ⇒ Boolean
51 52 53 |
# File 'lib/startback/operation.rb', line 51 def respond_to?(name, *args) super || (world && world.has_key?(name)) end |
#with_context(ctx = nil) ⇒ Object
55 56 57 58 59 60 61 |
# 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 |