Class: Sanford::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/sanford/runner.rb,
lib/sanford/runner.rb

Direct Known Subclasses

SanfordRunner, TestRunner

Defined Under Namespace

Classes: ResponseArgs

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#handlerObject (readonly)

Returns the value of attribute handler.



17
18
19
# File 'lib/sanford/runner.rb', line 17

def handler
  @handler
end

#handler_classObject (readonly)

Returns the value of attribute handler_class.



17
18
19
# File 'lib/sanford/runner.rb', line 17

def handler_class
  @handler_class
end

#loggerObject (readonly)

Returns the value of attribute logger.



18
19
20
# File 'lib/sanford/runner.rb', line 18

def logger
  @logger
end

#paramsObject (readonly)

Returns the value of attribute params.



18
19
20
# File 'lib/sanford/runner.rb', line 18

def params
  @params
end

#requestObject (readonly)

Returns the value of attribute request.



18
19
20
# File 'lib/sanford/runner.rb', line 18

def request
  @request
end

#routerObject (readonly)

Returns the value of attribute router.



18
19
20
# File 'lib/sanford/runner.rb', line 18

def router
  @router
end

#template_sourceObject (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, options = nil)
  options ||= {}
  message = options[:message] || options['message']
  response_status = [ status, message ]
  response_data = options[:data] || options['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

#runObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/sanford/runner.rb', line 33

def run
  raise NotImplementedError
end