Module: Hesburgh::Lib::ControllerWithRunner

Extended by:
ActiveSupport::Concern
Defined in:
lib/hesburgh/lib/controller_with_runner.rb

Overview

Exposes a way for connecting a set of Runners into your application. A runner allows you to tease out Action level logic into its own custom class.

See Also:

Defined Under Namespace

Classes: ImproperRunnerError, RunnerNotFoundError

Instance Method Summary collapse

Instance Method Details

#run(*args, &block) ⇒ Object

So you can more easily decouple the controller’s command behavior and response behavior.

Examples:

def index
  run(specific_params) do |on|
    on.success { |collection|
      @collection = collection
      respond_with(@collection)
    }
  end
end

See Also:

  • for customization


42
43
44
# File 'lib/hesburgh/lib/controller_with_runner.rb', line 42

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

#runner(runner_name = nil) ⇒ Object

A query to lookup the appropriate Runner class



47
48
49
50
51
52
# File 'lib/hesburgh/lib/controller_with_runner.rb', line 47

def runner(runner_name = nil)
  return @runner if @runner # For Dependency Injection
  runner_name = action_name.classify unless runner_name
  return runner_container.const_get(runner_name) if runner_container.const_defined?(runner_name)
  raise(RunnerNotFoundError, container: runner_container, name: runner_name)
end

#runner=(object) ⇒ Object

Exposed for purposes of Dependency Injection.



55
56
57
58
# File 'lib/hesburgh/lib/controller_with_runner.rb', line 55

def runner=(object)
  raise(ImproperRunnerError, runner: object, method_name: :run) unless object.respond_to?(:run)
  @runner = object
end