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, handler_class_name, handler_class = nil) ⇒ Route

Returns a new instance of Route.



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

def initialize(method, path, handler_class_name, handler_class = nil)
  @method = method
  @path   = path
  @handler_class_name = handler_class_name
  @handler_class      = handler_class
end

Instance Attribute Details

#handler_classObject (readonly)

Returns the value of attribute handler_class.



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

def handler_class
  @handler_class
end

#handler_class_nameObject (readonly)

Returns the value of attribute handler_class_name.



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

def handler_class_name
  @handler_class_name
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#constantize!Object



15
16
17
18
# File 'lib/deas/route.rb', line 15

def constantize!
  @handler_class ||= constantize_name(handler_class_name)
  raise(NoHandlerClassError.new(handler_class_name)) if !@handler_class
end

#run(sinatra_call) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/deas/route.rb', line 20

def run(sinatra_call)
  sinatra_call.request.env.tap do |env|
    env['sinatra.params']          = sinatra_call.params
    env['deas.handler_class_name'] = @handler_class_name
    env['deas.logging'].call "  Handler: #{env['deas.handler_class_name']}"
    env['deas.logging'].call "  Params:  #{env['sinatra.params'].inspect}"
  end
  Deas::SinatraRunner.run(@handler_class, sinatra_call)
end