Class | Merb::Rack::Console |
In: |
merb-core/lib/merb-core/rack/adapter/irb.rb
|
Parent: | Object |
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 merb-core/lib/merb-core/rack/adapter/irb.rb, line 113 113: def close_sandbox! 114: orm_modules.each { |orm| orm.close_sandbox! if orm.respond_to?(:close_sandbox!) } 115: puts "Modifications have been rolled back" 116: 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 merb-core/lib/merb-core/rack/adapter/irb.rb, line 102 102: def open_sandbox! 103: puts "Loading #{Merb.environment} environment in sandbox (Merb #{Merb::VERSION})" 104: puts "Any modifications you make will be rolled back on exit" 105: orm_modules.each { |orm| orm.open_sandbox! if orm.respond_to?(:open_sandbox!) } 106: end
Reloads classes using Merb::BootLoader::ReloadClasses. :api: public
# File merb-core/lib/merb-core/rack/adapter/irb.rb, line 65 65: def reload! 66: Merb::BootLoader::ReloadClasses.reload 67: end
Prints all routes for the application. :api: public
# File merb-core/lib/merb-core/rack/adapter/irb.rb, line 71 71: def show_routes 72: seen = [] 73: unless Merb::Router.named_routes.empty? 74: puts "==== Named routes" 75: Merb::Router.named_routes.each do |name,route| 76: # something weird happens when you combine sprintf and irb 77: puts "Helper : #{name}" 78: meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/ 79: puts "HTTP method: #{meth || 'GET'}" 80: puts "Route : #{route}" 81: puts "Params : #{route.params.inspect}" 82: puts 83: seen << route 84: end 85: end 86: puts "==== Anonymous routes" 87: (Merb::Router.routes - seen).each do |route| 88: meth = $1.upcase if route.conditions[:method].to_s =~ /(get|post|put|delete)/ 89: puts "HTTP method: #{meth || 'GET'}" 90: puts "Route : #{route}" 91: puts "Params : #{route.params.inspect}" 92: puts 93: end 94: nil 95: end
Explictly show logger output during IRB session :api: public
# File merb-core/lib/merb-core/rack/adapter/irb.rb, line 120 120: def trace_log! 121: Merb.logger.auto_flush = true 122: 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<Symbol>: | The name of the route. |
args<Hash>: | Parameters for the route generation. |
args<Hash>: | Parameters for the route generation. This route will use the default route. |
name<Symbol>: | The name of the route. |
args<Array>: | 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
match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, :title => "new_article")
Default Route
default_routes
end
url(:controller => "articles", :action => "new")
Anonymous Paramters
match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, 2008, 10, "test_article")
:api: public
# File merb-core/lib/merb-core/rack/adapter/irb.rb, line 58 58: def url(name, *args) 59: args << {} 60: Merb::Router.url(name, *args) 61: end