Class: Usher::Interface::Rack::Builder

Inherits:
Rack::Builder
  • Object
show all
Defined in:
lib/usher/interface/rack/builder.rb

Overview

Replacement for Builder which using Usher 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.



7
8
9
10
# File 'lib/usher/interface/rack/builder.rb', line 7

def initialize(&block)
  @usher = Usher::Interface::Rack.new
  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:



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

def delete(path, options = nil, &block)
  self.map(path, options.merge!(:conditions => {:request_method => "DELETE"}), &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
28
# File 'lib/usher/interface/rack/builder.rb', line 25

def get(path, options = nil, &block)
  self.map(path, options.merge!(:conditions => {:request_method => "HEAD"}), &block)
  self.map(path, options.merge!(:conditions => {:request_method => "GET"}), &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/usher/interface/rack/builder.rb', line 16

def map(path, options = nil, &block)
  @usher.add(path, options).to(&block)
  @ins << @usher unless @ins.last == @usher
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:



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

def post(path, options = nil, &block)
  self.map(path, options.merge!(:conditions => {:request_method => "POST"}), &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:



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

def put(path, options = nil, &block)
  self.map(path, options.merge!(:conditions => {:request_method => "PUT"}), &block)
end