Class: Deas::SinatraRunner

Inherits:
Runner
  • Object
show all
Defined in:
lib/deas/sinatra_runner.rb

Instance Attribute Summary

Attributes inherited from Runner

#app_settings, #logger, #params, #request, #response, #session

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler_class, sinatra_call) ⇒ SinatraRunner

Returns a new instance of SinatraRunner.



12
13
14
15
16
17
18
19
20
21
# File 'lib/deas/sinatra_runner.rb', line 12

def initialize(handler_class, sinatra_call)
  @sinatra_call  = sinatra_call
  @app_settings  = @sinatra_call.settings
  @logger        = @sinatra_call.settings.logger
  @params        = @sinatra_call.params
  @request       = @sinatra_call.request
  @response      = @sinatra_call.response
  @session       = @sinatra_call.session
  super(handler_class)
end

Class Method Details

.run(*args) ⇒ Object



8
9
10
# File 'lib/deas/sinatra_runner.rb', line 8

def self.run(*args)
  self.new(*args).run
end

Instance Method Details

#halt(*args) ⇒ Object

Helpers



33
34
35
# File 'lib/deas/sinatra_runner.rb', line 33

def halt(*args)
  @sinatra_call.halt(*args)
end

#redirect(*args) ⇒ Object



44
45
46
# File 'lib/deas/sinatra_runner.rb', line 44

def redirect(*args)
  @sinatra_call.redirect(*args)
end

#redirect_to(path, *args) ⇒ Object



48
49
50
# File 'lib/deas/sinatra_runner.rb', line 48

def redirect_to(path, *args)
  @sinatra_call.redirect(@sinatra_call.to(path), *args)
end

#render(name, options = nil, &block) ⇒ Object



37
38
39
40
41
42
# File 'lib/deas/sinatra_runner.rb', line 37

def render(name, options = nil, &block)
  options ||= {}
  options[:locals] = { :view => @handler }.merge(options[:locals] || {})
  options[:layout] ||= @handler_class.layouts
  Deas::Template.new(@sinatra_call, name, options).render(&block)
end

#runObject



23
24
25
26
27
28
29
# File 'lib/deas/sinatra_runner.rb', line 23

def run
  run_callbacks @handler_class.before_callbacks
  @handler.init
  response_data = @handler.run
  run_callbacks @handler_class.after_callbacks
  response_data
end