Class: Hesburgh::Lib::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/hesburgh/lib/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, though this is not considered exhaustive:

  • 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.

See Also:

  • Hesrbugh::Lib::MockRunner

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, callbacks: nil) {|@callbacks| ... } ⇒ Runner

Returns a new instance of Runner.

Yields:

  • (@callbacks)


27
28
29
30
31
# File 'lib/hesburgh/lib/runner.rb', line 27

def initialize(context, callbacks: nil)
  @callbacks = callbacks || default_callbacks
  @context = context
  yield(@callbacks) if block_given?
end

Class Method Details

.run(context, *args, &block) ⇒ Object



20
21
22
# File 'lib/hesburgh/lib/runner.rb', line 20

def self.run(context, *args, &block)
  new(context, &block).run(*args)
end

Instance Method Details

#callback(name, *args) ⇒ Object



33
34
35
36
# File 'lib/hesburgh/lib/runner.rb', line 33

def callback(name, *args)
  @callbacks.call(name, *args)
  return name, *args
end

#run(*_args) ⇒ Object

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/hesburgh/lib/runner.rb', line 38

def run(*_args)
  raise(NotImplementedError, "You must define #{self.class}#run")
end