Class: Sanford::Runner
- Inherits:
-
Object
- Object
- Sanford::Runner
- Defined in:
- lib/sanford/runner.rb,
lib/sanford/runner.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ResponseArgs
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#handler_class ⇒ Object
readonly
Returns the value of attribute handler_class.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
-
#template_source ⇒ Object
readonly
Returns the value of attribute template_source.
Instance Method Summary collapse
-
#halt(status, options = nil) ⇒ Object
It’s best to keep what ‘halt` and `catch_halt` return in the same format.
-
#initialize(handler_class, args = nil) ⇒ Runner
constructor
A new instance of Runner.
- #render(path, locals = nil) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(handler_class, args = nil) ⇒ Runner
Returns a new instance of Runner.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sanford/runner.rb', line 20 def initialize(handler_class, args = nil) @handler_class = handler_class a = args || {} @request = a[:request] @params = a[:params] || {} @logger = a[:logger] || Sanford::NullLogger.new @router = a[:router] || Sanford::Router.new @template_source = a[:template_source] || Sanford::NullTemplateSource.new @handler = @handler_class.new(self) end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
17 18 19 |
# File 'lib/sanford/runner.rb', line 17 def handler @handler end |
#handler_class ⇒ Object (readonly)
Returns the value of attribute handler_class.
17 18 19 |
# File 'lib/sanford/runner.rb', line 17 def handler_class @handler_class end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
18 19 20 |
# File 'lib/sanford/runner.rb', line 18 def logger @logger end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
18 19 20 |
# File 'lib/sanford/runner.rb', line 18 def params @params end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
18 19 20 |
# File 'lib/sanford/runner.rb', line 18 def request @request end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
18 19 20 |
# File 'lib/sanford/runner.rb', line 18 def router @router end |
#template_source ⇒ Object (readonly)
Returns the value of attribute template_source.
18 19 20 |
# File 'lib/sanford/runner.rb', line 18 def template_source @template_source end |
Instance Method Details
#halt(status, options = nil) ⇒ Object
It’s best to keep what ‘halt` and `catch_halt` return in the same format. Currently this is a `ResponseArgs` object. This is so no matter how the block returns (either by throwing or running normally), you get the same thing kind of object.
46 47 48 49 50 51 52 |
# File 'lib/sanford/runner.rb', line 46 def halt(status, = nil) ||= {} = [:message] || ['message'] response_status = [ status, ] response_data = [:data] || ['data'] throw :halt, ResponseArgs.new(response_status, response_data) end |
#render(path, locals = nil) ⇒ Object
37 38 39 |
# File 'lib/sanford/runner.rb', line 37 def render(path, locals = nil) self.template_source.render(path, self.handler, locals || {}) end |
#run ⇒ Object
33 34 35 |
# File 'lib/sanford/runner.rb', line 33 def run raise NotImplementedError end |