module Hesburgh::Lib::ControllerWithRunner

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 Hesburgh::Lib::Runner

Public Instance Methods

run(*args, &block) click to toggle source

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

@example

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

@see .runner_container for customization

# File lib/hesburgh/lib/controller_with_runner.rb, line 42
def run(*args, &block)
  runner.run(self, *args, &block)
end
runner(runner_name = nil) click to toggle source

A query to lookup the appropriate Runner class

# 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) click to toggle source

Exposed for purposes of Dependency Injection.

# 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