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.
Defined Under Namespace
Classes: ImproperRunnerError, RunnerNotFoundError
Instance Method Summary collapse
-
#run(*args, &block) ⇒ Object
So you can more easily decouple the controller’s command behavior and response behavior.
-
#runner(runner_name = nil) ⇒ Object
A query to lookup the appropriate Runner class.
-
#runner=(object) ⇒ Object
Exposed for purposes of Dependency Injection.
Instance Method Details
#run(*args, &block) ⇒ Object
So you can more easily decouple the controller’s command behavior and response behavior.
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 |