Ends a sandboxed session (delegates to any Merb::Orms::* modules).
An ORM should implement Merb::Orms::MyOrm#close_sandbox! to support this. Usually this involves rolling back a transaction. :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 155 155: def close_sandbox! 156: orm_modules.each { |orm| orm.close_sandbox! if orm.respond_to?(:close_sandbox!) } 157: puts "Modifications have been rolled back" 158: end
Starts a sandboxed session (delegates to any Merb::Orms::* modules).
An ORM should implement Merb::Orms::MyOrm#open_sandbox! to support this. Usually this involves starting a transaction. :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 144 144: def open_sandbox! 145: puts "Loading #{Merb.environment} environment in sandbox (Merb #{Merb::VERSION})" 146: puts "Any modifications you make will be rolled back on exit" 147: orm_modules.each { |orm| orm.open_sandbox! if orm.respond_to?(:open_sandbox!) } 148: end
Reloads classes using Merb::BootLoader::ReloadClasses. :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 99 99: def reload! 100: Merb::BootLoader::ReloadClasses.reload! 101: end
Generates a URL for a single or nested resource.
resources | The resources for which the URL |
should be generated. These resources should be specified in the router.rb file using #resources and #resource.
options | Any extra parameters that are needed to |
generate the URL.
String | The generated URL. |
Merb::Router.prepare do
resources :users do resources :comments end
end
resource(:users) # => /users resource(@user) # => /users/10 resource(@user, :comments) # => /users/10/comments resource(@user, @comment) # => /users/10/comments/15 resource(:users, :new) # => /users/new resource(:@user, :edit) # => /users/10/edit
:api: public
# File lib/merb-core/rack/adapter/irb.rb, line 92 92: def resource(*args) 93: args << {} 94: Merb::Router.resource(*args) 95: end
Returns a request for a specific URL and method. :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 105 105: def route_to(url, method = :get, env_overrides = {}) 106: request_env = ::Rack::MockRequest.env_for(url) 107: request_env["REQUEST_METHOD"] = method.to_s 108: Merb::Router.route_for(Merb::Request.new(request_env.merge(env_overrides))) 109: end
Prints all routes for the application. :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 113 113: def show_routes 114: seen = [] 115: unless Merb::Router.named_routes.empty? 116: puts "==== Named routes" 117: Merb::Router.named_routes.each do |name,route| 118: # something weird happens when you combine sprintf and irb 119: puts "Helper : #{name}" 120: meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/ 121: puts "HTTP method: #{meth || 'GET'}" 122: puts "Route : #{route}" 123: puts "Params : #{route.params.inspect}" 124: puts 125: seen << route 126: end 127: end 128: puts "==== Anonymous routes" 129: (Merb::Router.routes - seen).each do |route| 130: meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/ 131: puts "HTTP method: #{meth || 'GET'}" 132: puts "Route : #{route}" 133: puts "Params : #{route.params.inspect}" 134: puts 135: end 136: nil 137: end
Explictly show logger output during IRB session :api: public
# File lib/merb-core/rack/adapter/irb.rb, line 162 162: def trace_log! 163: Merb.logger.auto_flush = true 164: end
There are three possible ways to use this method. First, if you have a named route, you can specify the route as the first parameter as a symbol and any paramters in a hash. Second, you can generate the default route by just passing the params hash, just passing the params hash. Finally, you can use the anonymous parameters. This allows you to specify the parameters to a named route in the order they appear in the router.
name | The name of the route. |
args | Parameters for the route generation. |
args | Parameters for the route generation. This route will use the default route. |
name | The name of the route. |
args | An array of anonymous parameters to generate the route with. These parameters are assigned to the route parameters in the order that they are passed. |
String | The generated URL. |
Named Route
Merb::Router.prepare do
match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, :title => “new_article“)
Default Route
Merb::Router.prepare do
default_routes
end
url(:controller => “articles”, :action => “new”)
Anonymous Paramters
Merb::Router.prepare do
match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, 2008, 10, “test_article“)
:api: public
# File lib/merb-core/rack/adapter/irb.rb, line 58 58: def url(name, *args) 59: args << {} 60: Merb::Router.url(name, *args) 61: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.