Module: Truss::Router

Extended by:
Router
Included in:
Router
Defined in:
lib/truss/router.rb,
lib/truss/router/node.rb,
lib/truss/router/routes.rb,
lib/truss/router/request.rb,
lib/truss/router/version.rb,
lib/truss/router/routeset.rb,
lib/truss/router/routes/get.rb,
lib/truss/router/routes/put.rb,
lib/truss/router/routes/head.rb,
lib/truss/router/routes/post.rb,
lib/truss/router/routes/patch.rb,
lib/truss/router/routes/delete.rb,
lib/truss/router/routes/options.rb

Defined Under Namespace

Modules: Routes Classes: Node, Request, Routeset

Constant Summary collapse

VERSION =
"0.0.5"

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/truss/router.rb', line 52

def call env
    request = Request.new(env.dup)
    route = routeset.find_route(request)   
    if route
        route.call(request)
    else
        [404, {'Content-Type' => 'text/plain'}, ["Not Found"]]
    end
end

#delete(path, endpoint, opts = {}) ⇒ Object



44
45
46
# File 'lib/truss/router.rb', line 44

def delete(path, endpoint, opts={})
    build_node :Delete, path, endpoint, opts
end

#draw(&block) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/truss/router.rb', line 11

def draw(&block)
    raise ArgumentError unless block_given?
    block.call(self)
end

#get(path, endpoint, opts = {}) ⇒ Object



20
21
22
# File 'lib/truss/router.rb', line 20

def get(path, endpoint, opts={})
    build_node :Get, path, endpoint, opts
end

#head(path, endpoint, opts = {}) ⇒ Object



32
33
34
# File 'lib/truss/router.rb', line 32

def head(path, endpoint, opts={})
    build_node :Head, path, endpoint, opts
end

#options(path, endpoint, opts = {}) ⇒ Object



28
29
30
# File 'lib/truss/router.rb', line 28

def options(path, endpoint, opts={})
    build_node :Options, path, endpoint, opts
end

#patch(path, endpoint, opts = {}) ⇒ Object



40
41
42
# File 'lib/truss/router.rb', line 40

def patch(path, endpoint, opts={})
    build_node :Patch, path, endpoint, opts
end

#post(path, endpoint, opts = {}) ⇒ Object



24
25
26
# File 'lib/truss/router.rb', line 24

def post(path, endpoint, opts={})
    build_node :Post, path, endpoint, opts
end

#put(path, endpoint, opts = {}) ⇒ Object



36
37
38
# File 'lib/truss/router.rb', line 36

def put(path, endpoint, opts={})
    build_node :Put, path, endpoint, opts
end

#reset!Object



48
49
50
# File 'lib/truss/router.rb', line 48

def reset!
    @routeset = Truss::Router::Routeset.new
end

#routesetObject



16
17
18
# File 'lib/truss/router.rb', line 16

def routeset
    @routeset ||= Truss::Router::Routeset.new
end