Class: Rack::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/rack/rack_mapper.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

Constructor Details

#initialize(&block) ⇒ Builder

Returns a new instance of Builder.



4
5
6
# File 'lib/ext/rack/rack_mapper.rb', line 4

def initialize(&block)
  super
end

Instance Method Details

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

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

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: nil)

    Options for added path.

See Also:



49
50
51
# File 'lib/ext/rack/rack_mapper.rb', line 49

def delete(path, options = nil, &block)
  router.delete(path).with_options(options).to(&block)
end

#get(path, options = nil, &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: nil)

    Options for added path.

See Also:



25
26
27
# File 'lib/ext/rack/rack_mapper.rb', line 25

def get(path, options = nil, &block)
  router.get(path).with_options(options).to(&block)
end

#head(path, options = nil, &block) ⇒ Object

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

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: nil)

    Options for added path.

See Also:



57
58
59
# File 'lib/ext/rack/rack_mapper.rb', line 57

def head(path, options = nil, &block)
  router.head(path).with_options(options).to(&block)
end

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

Maps a path to a block.

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: nil)

    Options for added path.

See Also:



16
17
18
19
# File 'lib/ext/rack/rack_mapper.rb', line 16

def map(path, options = nil, &block)
  router.add(path).with_options(options).to(&block)
  @ins << router unless @ins.last == router
end

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

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

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: nil)

    Options for added path.

See Also:



33
34
35
# File 'lib/ext/rack/rack_mapper.rb', line 33

def post(path, options = nil, &block)
  router.post(path).with_options(options).to(&block)
end

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

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

Parameters:

  • path (String)

    Path to map to.

  • options (Hash) (defaults to: nil)

    Options for added path.

See Also:



41
42
43
# File 'lib/ext/rack/rack_mapper.rb', line 41

def put(path, options = nil, &block)
  router.put(path).with_options(options).to(&block)
end

#routerObject



8
9
10
# File 'lib/ext/rack/rack_mapper.rb', line 8

def router
  @router ||= HttpRouter.new
end