Sha256: 7a75645c18cc3a6b293c7099427d867bc2296f0dcc101c19881846126a3b3ef5

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

module Rack::App::SingletonMethods::HttpMethods

  def get(path = '/', &block)
    add_route('GET', path, &block)
  end

  def post(path = '/', &block)
    add_route('POST', path, &block)
  end

  def put(path = '/', &block)
    add_route('PUT', path, &block)
  end

  def head(path = '/', &block)
    add_route('HEAD', path, &block)
  end

  def delete(path = '/', &block)
    add_route('DELETE', path, &block)
  end

  def options(path = '/', &block)
    add_route('OPTIONS', path, &block)
  end

  def patch(path = '/', &block)
    add_route('PATCH', path, &block)
  end

  def alias_endpoint(new_request_path, original_request_path)
    router.endpoints.select { |ep| ep[:request_path] == original_request_path }.each do |endpoint|
      router.register_endpoint!(endpoint[:request_method], new_request_path, endpoint[:description], endpoint[:endpoint])
    end
  end

  def serve_files_from(file_path, options={})
    file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(file_path))
    request_path = Rack::App::Utils.join(@namespaces, options[:to], '**', '*')
    router.register_endpoint!('GET', request_path, @last_description, file_server)
    @last_description = nil
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-app-2.1.0 lib/rack/app/singleton_methods/http_methods.rb
rack-app-2.0.0 lib/rack/app/singleton_methods/http_methods.rb