Module: HttpRouter::Rack::BuilderMixin

Included in:
Builder
Defined in:
lib/http_router/rack/builder.rb

Overview

Replacement for Builder which using HttpRouter to map requests instead of a simple Hash. As well, add convenience methods for the request methods.

Instance Method Summary collapse

Instance Method Details

#delete(path, options = {}, &block) ⇒ Object

Maps a path with request methods ‘DELETE` to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: {})

    Options for added path.

See Also:



50
51
52
# File 'lib/http_router/rack/builder.rb', line 50

def delete(path, options = {}, &block)
  map(path, options, :delete, &block)
end

#get(path, options = {}, &block) ⇒ Object

Maps a path with request methods ‘HEAD` and `GET` to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: {})

    Options for added path.

See Also:



26
27
28
# File 'lib/http_router/rack/builder.rb', line 26

def get(path, options = {}, &block)
  map(path, options, :get, &block)
end

#map(path, options = {}, method = nil, &block) ⇒ Object

Maps a path to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: {})

    Options for added path.

See Also:



14
15
16
17
18
19
20
# File 'lib/http_router/rack/builder.rb', line 14

def map(path, options = {}, method = nil, &block)
  route = router.add(path, options)
  route.send(method) if method
  route.to(&block)
  @ins << router unless @ins.last == router
  route
end

#options(path, options = {}, &block) ⇒ Object



54
55
56
# File 'lib/http_router/rack/builder.rb', line 54

def options(path, options = {}, &block)
  map(path, options, :options, &block)
end

#post(path, options = {}, &block) ⇒ Object

Maps a path with request methods ‘POST` to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: {})

    Options for added path.

See Also:



34
35
36
# File 'lib/http_router/rack/builder.rb', line 34

def post(path, options = {}, &block)
  map(path, options, :post, &block)
end

#put(path, options = {}, &block) ⇒ Object

Maps a path with request methods ‘PUT` to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: {})

    Options for added path.

See Also:



42
43
44
# File 'lib/http_router/rack/builder.rb', line 42

def put(path, options = {}, &block)
  map(path, options, :put, &block)
end

#routerObject



6
7
8
# File 'lib/http_router/rack/builder.rb', line 6

def router
  @router ||= HttpRouter.new
end