Sha256: e0c1027b769e315cf3a1749c57a0a220f729243de5cb3e05f480b7eb872a8d87

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

class Usher
  module Interface
    class Rack
      # Replacement for <tt>Rack::Builder</tt> which using Usher to map requests instead of a simple Hash.
      # As well, add convenience methods for the request methods.
      #
      class Builder < ::Rack::Builder
        def initialize(&block)
          @usher = Usher::Interface::Rack.new
          super
        end

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

        # it returns route, and because you may want to work with the route,
        # for example give it a name, we returns the route with GET request
        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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
usher-0.7.4 lib/usher/interface/rack/builder.rb
usher-0.7.3 lib/usher/interface/rack/builder.rb
usher-0.7.2 lib/usher/interface/rack/builder.rb