Class: SinatraMore::NamedRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra_more/routing_plugin/named_route.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, *names) ⇒ 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)



6
7
8
9
# File 'lib/sinatra_more/routing_plugin/named_route.rb', line 6

def initialize(app, *names)
  @app   = app
  @names = names.flatten
end

Instance Method Details

#map(*args, &block) ⇒ Object

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’)



21
22
23
# File 'lib/sinatra_more/routing_plugin/named_route.rb', line 21

def map(*args, &block)
  @app.map(*args.unshift(@names), &block)
end

#to(path) ⇒ Object

Used to define the url mapping to the supplied alias NamedRoute.new(@app, :account).to(‘/account/path’)



13
14
15
# File 'lib/sinatra_more/routing_plugin/named_route.rb', line 13

def to(path)
  @app.named_paths[@names.unshift(@app.app_name)] = path
end