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