Sha256: b85ae70450ed6b21dc5ebb27e4535f06fb15d1f6ddc546099f47829d9d98b64f

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

module Galago
  class Router
    class DSL
      def initialize(router, block)
        @router = router
        @namespace = ''
        instance_eval(&block)
      end

      def namespace(new_namespace)
        @namespace << "/#{new_namespace}"
        yield
        @namespace = ''
      end

      def get(path, options)
        add_route("GET", path, options[:to])
        add_route("HEAD", path, Rack::Head.new(options[:to]))
      end

      def patch(path, options)
        add_route("PATCH", path, options[:to])
      end

      def post(path, options)
        add_route("POST", path, options[:to])
      end

      def put(path, options)
        add_route("PUT", path, options[:to])
      end

      def delete(path, options)
        add_route("DELETE", path, options[:to])
      end

      private

      def add_route(method, path, application)
        path_with_namespace = Path.join(@namespace, path)
        @router.add_route(method, path_with_namespace, application)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
galago-router-0.2.0 lib/galago/router/dsl.rb