class Sanford::Runner
Constants
- DEFAULT_DATA
- DEFAULT_STATUS_CODE
- DEFAULT_STATUS_MSG
Attributes
handler[R]
handler_class[R]
logger[R]
params[R]
request[R]
router[R]
template_source[R]
Public Class Methods
new(handler_class, args = nil)
click to toggle source
# File lib/sanford/runner.rb, line 23 def initialize(handler_class, args = nil) @status_code, @status_msg, @data = nil, nil, nil args ||= {} @logger = args[:logger] || Sanford::NullLogger.new @router = args[:router] || Sanford::Router.new @template_source = args[:template_source] || Sanford::NullTemplateSource.new @request = args[:request] @params = args[:params] || {} @handler_class = handler_class @handler = @handler_class.new(self) end
Public Instance Methods
data(value = nil)
click to toggle source
# File lib/sanford/runner.rb, line 56 def data(value = nil) @data = value if !value.nil? @data end
halt(*args)
click to toggle source
# File lib/sanford/runner.rb, line 61 def halt(*args) self.status(*args) self.data((args.pop)[:data]) if args.last.kind_of?(::Hash) throw :halt end
partial(path, locals = nil)
click to toggle source
# File lib/sanford/runner.rb, line 71 def partial(path, locals = nil) self.data(self.template_source.partial(path, locals || {})) end
render(path, locals = nil)
click to toggle source
# File lib/sanford/runner.rb, line 67 def render(path, locals = nil) self.data(self.template_source.render(path, self.handler, locals || {})) end
run()
click to toggle source
# File lib/sanford/runner.rb, line 37 def run raise NotImplementedError end
status(*args)
click to toggle source
# File lib/sanford/runner.rb, line 48 def status(*args) if !args.empty? @status_msg = (args.pop)[:message] if args.last.kind_of?(::Hash) @status_code = args.first if !args.empty? end [@status_code, @status_msg] end
to_response()
click to toggle source
# File lib/sanford/runner.rb, line 41 def to_response Sanford::Protocol::Response.new( [@status_code || DEFAULT_STATUS_CODE, @status_msg || DEFAULT_STATUS_MSG], @data.nil? ? DEFAULT_DATA : @data ) end