Module: BigBand::AdvancedRoutes

Defined in:
lib/big_band/advanced_routes.rb

Overview

AdvancedRoutes makes routes first class objects in Sinatra:

require "sinatra"
require "big_band"

admin_route = get "/admin" do
  administrate_stuff
end

before do
  # Let's deactivate the route if we have no password file.
  if File.exists? "admin_password"
    admin_route.activate
  else
    admin_route.deactivate 
  end
end

first_route = get "/:name" do
  # stuff
end

other_route = get "/foo_:name" do
  # other stuff
end

# Unfortunatly first_route will catch all the requests other_route would
# have gotten, since it has been defined first. But wait, we can fix this!
other_route.promote

Defined Under Namespace

Modules: ArrayMethods, ClassMethods, Route

Class Method Summary collapse

Class Method Details

.registered(klass) ⇒ Object



177
178
179
180
181
182
183
184
185
# File 'lib/big_band/advanced_routes.rb', line 177

def self.registered(klass)
  klass.extend ClassMethods
  klass.routes.each do |verb, routes|
    routes.each do |route|
      route.to_route! verb, :app => klass
      klass.send :invoke_hook, :advanced_root_added, route
    end
  end
end