Sha256: bbe4157a49f7049adb30d51b5a611a405e082f502551aa3522889edf85c952c9

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

module Rack::App::SingletonMethods::RouteHandling

  def router
    @router ||= Rack::App::Router.new
  end

  protected

  def root(endpoint_path)
    alias_endpoint '/', endpoint_path
  end

  def description(*description_texts)
    @last_description = description_texts.join("\n")
  end

  alias desc description

  def add_route(request_method, request_path, &block)

    request_path = ::Rack::App::Utils.join(@namespaces, request_path)

    builder = Rack::Builder.new
    middlewares.each do |builder_block|
      builder_block.call(builder)
    end

    properties = {
        :user_defined_logic => block,
        :request_method => request_method,
        :request_path => request_path,

        :error_handler => error,
        :description => @last_description,
        :serializer => serializer,
        :middleware => builder,
        :app_class => self
    }


    endpoint = Rack::App::Endpoint.new(properties)
    router.register_endpoint!(request_method, request_path, @last_description, endpoint)

    @last_description = nil
    return endpoint

  end

  def namespace(request_path_namespace)
    return unless block_given?
    @namespaces ||= []
    @namespaces.push(request_path_namespace)
    yield
    @namespaces.pop
    nil
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-app-3.6.0 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.5.2 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.5.1 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.5.0 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.4.0 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.3.0 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.2.1 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.2.0 lib/rack/app/singleton_methods/route_handling.rb
rack-app-3.1.0 lib/rack/app/singleton_methods/route_handling.rb