Sha256: 7172f010aec59070bec8357fc8ccc3a8a306f7540d18227e497c0194dfe73e73

Contents?: true

Size: 1.07 KB

Versions: 9

Compression:

Stored size: 1.07 KB

Contents

module Padrino
  module Routing
    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
      # Appends the application name to front of route if necessary
      # NamedRoute.new(@app, :account).to('/account/path')
      def to(path)
        @names.unshift(@app.app_name.to_sym) unless @names.first == @app.app_name.to_sym
        @app.named_paths[@names] = 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

9 entries across 9 versions & 1 rubygems

Version Path
padrino-routing-0.5.0 lib/padrino-routing/named_route.rb
padrino-routing-0.4.6 lib/padrino-routing/named_route.rb
padrino-routing-0.4.5 lib/padrino-routing/named_route.rb
padrino-routing-0.2.9 lib/padrino-routing/named_route.rb
padrino-routing-0.2.6 lib/padrino-routing/named_route.rb
padrino-routing-0.2.5 lib/padrino-routing/named_route.rb
padrino-routing-0.2.2 lib/padrino-routing/named_route.rb
padrino-routing-0.2.1 lib/padrino-routing/named_route.rb
padrino-routing-0.2.0 lib/padrino-routing/named_route.rb