Sha256: e547961805e8732192ff9e0abf0a6a96cab6f088b49b098ebadfc72eaf4f65e6

Contents?: true

Size: 1.68 KB

Versions: 3

Compression:

Stored size: 1.68 KB

Contents

require 'http_router/route'

module Hanami
  module Routing
    # Entry of the routing system
    #
    # @api private
    #
    # @since 0.1.0
    #
    # @see http://rdoc.info/gems/http_router/HttpRouter/Route
    #
    # @example
    #   require 'hanami/router'
    #
    #   router = Hanami::Router.new
    #   router.get('/', to: endpoint) # => #<Hanami::Routing::Route:0x007f83083ba028 ...>
    class Route < HttpRouter::Route
      # Asks the given resolver to return an endpoint that will be associated
      #   with the other options.
      #
      # @param resolver [Hanami::Routing::EndpointResolver, #resolve] this may change
      #   according to the :resolve option passed to Hanami::Router#initialize.
      #
      # @param options [Hash] options to customize the route
      # @option options [Symbol] :as the name we want to use for the route
      #
      # @since 0.1.0
      #
      # @api private
      #
      # @see Hanami::Router#initialize
      #
      # @example
      #   require 'hanami/router'
      #
      #   router = Hanami::Router.new
      #   router.get('/', to: endpoint, as: :home_page).name # => :home_page
      #
      #   router.path(:home_page) # => '/'
      def generate(resolver, options = {}, &endpoint)
        self.to   = resolver.resolve(options, &endpoint)
        self.name = options[:as].to_sym if options[:as]
        self
      end

      # Introspect the given route to understand if there is a wrapped
      # Hanami::Router
      #
      # @since 0.2.0
      # @api private
      def nested_router
        dest.routes if dest.respond_to?(:routes)
      end

      private
      def to=(dest = nil, &blk)
        self.to dest, &blk
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-router-0.6.2 lib/hanami/routing/route.rb
hanami-router-0.6.1 lib/hanami/routing/route.rb
hanami-router-0.6.0 lib/hanami/routing/route.rb