Class: Deas::Route

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, route_proxy) ⇒ Route

Returns a new instance of Route.



9
10
11
# File 'lib/deas/route.rb', line 9

def initialize(method, path, route_proxy)
  @method, @path, @route_proxy = method, path, route_proxy
end

Instance Attribute Details

#handler_classObject (readonly)

Returns the value of attribute handler_class.



7
8
9
# File 'lib/deas/route.rb', line 7

def handler_class
  @handler_class
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/deas/route.rb', line 7

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/deas/route.rb', line 7

def path
  @path
end

#route_proxyObject (readonly)

Returns the value of attribute route_proxy.



7
8
9
# File 'lib/deas/route.rb', line 7

def route_proxy
  @route_proxy
end

Instance Method Details

#run(sinatra_call) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deas/route.rb', line 18

def run(sinatra_call)
  runner = SinatraRunner.new(self.handler_class, {
    :sinatra_call => sinatra_call,
    :request      => sinatra_call.request,
    :response     => sinatra_call.response,
    :session      => sinatra_call.session,
    :params       => sinatra_call.params,
    :logger       => sinatra_call.settings.logger,
    :router       => sinatra_call.settings.router,
    :template_source => sinatra_call.settings.template_source
  })

  sinatra_call.request.env.tap do |env|
    env['deas.params'] = runner.params
    env['deas.handler_class_name'] = self.handler_class.name
    env['deas.logging'].call "  Handler: #{env['deas.handler_class_name']}"
    env['deas.logging'].call "  Params:  #{env['deas.params'].inspect}"
  end
  runner.run
end

#validate!Object



13
14
15
16
# File 'lib/deas/route.rb', line 13

def validate!
  @route_proxy.validate!
  @handler_class = @route_proxy.handler_class
end