Class: Funnel::Routing::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/funnel/routing/routes.rb

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoutes

Returns a new instance of Routes.



17
18
19
# File 'lib/funnel/routing/routes.rb', line 17

def initialize
  @routes = {}
end

Class Method Details

.draw {|@@instance| ... } ⇒ Object

Yields:

  • (@@instance)


12
13
14
15
# File 'lib/funnel/routing/routes.rb', line 12

def self.draw
  @@instance = Routes.new unless @@instance
  yield @@instance
end

.get_handler(path) ⇒ Object



8
9
10
# File 'lib/funnel/routing/routes.rb', line 8

def self.get_handler path
  @@instance.get_handler(path)
end

Instance Method Details

#connect(path, opts) ⇒ Object



21
22
23
# File 'lib/funnel/routing/routes.rb', line 21

def connect path, opts
  @routes[path] = Route.new(path, opts)
end

#default(opts) ⇒ Object



25
26
27
# File 'lib/funnel/routing/routes.rb', line 25

def default opts
  @routes[:default] = Route.new(:default, opts)
end

#get_defaultObject



29
30
31
# File 'lib/funnel/routing/routes.rb', line 29

def get_default
  @routes.key?(:default) ? @routes[:default].handler : nil
end

#get_handler(path) ⇒ Object



33
34
35
# File 'lib/funnel/routing/routes.rb', line 33

def get_handler path
  @routes.key?(path) ? @routes[path].handler : get_default
end