Class: Hydramata::Core::Runner
- Inherits:
-
Object
- Object
- Hydramata::Core::Runner
- Defined in:
- lib/hydramata/core/runner.rb
Overview
A Runner is responsible for performing the guts of what might traditionally be a controller’s action.
It exists for two reasons:
-
Controllers are extremely over-worked (parameter negotiation, authentication, authorization, marshalling an object, user messages via flash, and http response determination)
-
The inner method content of a controller’s action is subject to change especially as other implementors look to change the behavior.
So, the Runner provides a seem in the code in which you can more readily make changes to the “inner method” of a route. In some ways, I see this as a separation of state change and response; a somewhat analogous separation to the Command/Query separation principle.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
Instance Method Summary collapse
- #callback(name, *args) ⇒ Object
-
#initialize(context, collaborators = {}) {|@callbacks| ... } ⇒ Runner
constructor
A new instance of Runner.
- #run(*args) ⇒ Object
- #services ⇒ Object
Constructor Details
#initialize(context, collaborators = {}) {|@callbacks| ... } ⇒ Runner
Returns a new instance of Runner.
26 27 28 29 30 |
# File 'lib/hydramata/core/runner.rb', line 26 def initialize(context, collaborators = {}) @callbacks = collaborators.fetch(:callbacks) { default_callbacks } self.context = context yield(@callbacks) if block_given? end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
20 21 22 |
# File 'lib/hydramata/core/runner.rb', line 20 def context @context end |
Class Method Details
.run(context, *args, &block) ⇒ Object
22 23 24 |
# File 'lib/hydramata/core/runner.rb', line 22 def self.run(context,*args,&block) new(context, &block).run(*args) end |
Instance Method Details
#callback(name, *args) ⇒ Object
32 33 34 35 |
# File 'lib/hydramata/core/runner.rb', line 32 def callback(name, *args) @callbacks.call(name, *args) args end |
#run(*args) ⇒ Object
41 42 43 |
# File 'lib/hydramata/core/runner.rb', line 41 def run(*args) raise NotImplementedError.new("You must define #{self.class}#run") end |
#services ⇒ Object
37 38 39 |
# File 'lib/hydramata/core/runner.rb', line 37 def services context.services end |