Sha256: b34a28c70fb172de9e2da48abe5d6df04b9fd1885f213891289d2b8e6a507e1f

Contents?: true

Size: 969 Bytes

Versions: 4

Compression:

Stored size: 969 Bytes

Contents

module Sinatra
  module RoutingPlugin
    class NamedRoute
      # Constructs the NamedRoute which accepts the application and
      # the route alias names to register (i.e [:account] or [:admin, :show])
      # NamedRoute.new(@app, :admin, :show)
      def initialize(app, *names)
        @app   = app
        @names = names.flatten
      end

      # Used to define the url mapping to the supplied alias
      # NamedRoute.new(@app, :account).to('/account/path')
      def to(path)
        @app.named_paths[@names.unshift(@app.app_name)] = path
      end

      # Used to define the url mappings for child aliases within a namespace
      # Invokes map on the application itself, appending the namespace to the route
      # NamedRoute.new(@app, :admin).map(:show).to('/admin/show')
      # is equivalent to NamedRoute.new(@app, :admin, :show).to('/admin/show')
      def map(*args, &block)
        @app.map(*args.unshift(@names), &block)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
darkhelmet-sinatra_more-0.3.36 lib/sinatra/routing_plugin/named_route.rb
darkhelmet-sinatra_more-0.3.35 lib/sinatra/routing_plugin/named_route.rb
darkhelmet-sinatra_more-0.3.34 lib/sinatra/routing_plugin/named_route.rb
darkhelmet-sinatra_more-0.3.33 lib/sinatra/routing_plugin/named_route.rb