Class: Peictt::Builder::Router
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
4
5
6
7
|
# File 'lib/peictt/builder/router.rb', line 4
def initialize
@routes = []
@placeholders = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, url, args = {}) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/peictt/builder/router.rb', line 24
def method_missing(name, url, args = {})
verb = name.to_s.upcase
verb_class = Object.const_get "Peictt::Http::#{verb}"
route = verb_class.new url, args
@routes << route unless route_exists? route
route
end
|
Instance Method Details
13
14
15
|
# File 'lib/peictt/builder/router.rb', line 13
def all
@routes
end
|
#draw(&block) ⇒ Object
9
10
11
|
# File 'lib/peictt/builder/router.rb', line 9
def draw(&block)
instance_eval(&block)
end
|
#respond_to_missing?(type, include_private = false) ⇒ Boolean
41
42
43
|
# File 'lib/peictt/builder/router.rb', line 41
def respond_to_missing?(type, include_private = false)
super
end
|
#root(arg) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/peictt/builder/router.rb', line 17
def root(arg)
url = "/"
route = Peictt::Http::GET.new url, to: arg
@routes << route
route
end
|
#route_exists?(route) ⇒ Boolean
32
33
34
35
36
37
38
39
|
# File 'lib/peictt/builder/router.rb', line 32
def route_exists?(route)
@routes.each do |r|
if r.url == route.url
return true
end
end
false
end
|