Sha256: 7f8953bbaf804e856e6159da88d2375e151b5132688c0f4e2df82bb050ac9526

Contents?: true

Size: 903 Bytes

Versions: 25

Compression:

Stored size: 903 Bytes

Contents

module SinatraMore
  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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sinatra_more-0.3.43 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.42 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.41 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.40 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.39 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.38 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.37 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.36 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.35 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.34 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.33 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.32 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.31 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.30 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.29 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.28 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.27 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.26 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.25 lib/sinatra_more/routing_plugin/named_route.rb
sinatra_more-0.3.24 lib/sinatra_more/routing_plugin/named_route.rb