Class: Merb::Rack::Console

Inherits:
Object show all
Defined in:
lib/merb-core/rack/adapter/irb.rb

Instance Method Summary collapse

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.



63
64
65
66
# File 'lib/merb-core/rack/adapter/irb.rb', line 63

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.



53
54
55
56
57
# File 'lib/merb-core/rack/adapter/irb.rb', line 53

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.



18
19
20
# File 'lib/merb-core/rack/adapter/irb.rb', line 18

def reload!
  Merb::BootLoader::ReloadClasses.reload
end

#show_routesObject

Prints all routes for the application.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/merb-core/rack/adapter/irb.rb', line 23

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



69
70
71
# File 'lib/merb-core/rack/adapter/irb.rb', line 69

def trace_log!
  Merb.logger.auto_flush = true
end

#url(name, params = {}) ⇒ Object

Parameters

name<~to_sym, Hash>

The name of the route to generate.

params<Hash>

The params to use in the route generation.

Returns

String

The generated URL.

Alternatives

If name is a hash, it will be merged with params.



13
14
15
# File 'lib/merb-core/rack/adapter/irb.rb', line 13

def url(name, params={})
  Merb::Router.generate(name, params)
end