Skip to content

Commit

Permalink
Merge branch 'master' of github.com:judy/dotmatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
judy-zz committed Jan 17, 2014
2 parents 8f8aab7 + 6834b20 commit 8e9bbbe
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gemrc
@@ -0,0 +1,3 @@
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri

46 changes: 46 additions & 0 deletions .irbrc
@@ -0,0 +1,46 @@
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
require 'irbtools'

# Put this in your ~/.irbrc for easy rails route scanning
#
# Usage:
# > routes
# => prints all routes
# > routes /GET.*user/i
# => prints routes matching a given regex
# > routes "user"
# => matches strings as well

if defined? Rails

if Rails::VERSION::STRING >= "4"

# returns an array of routes in Rails 4
def formatted_routes
r = Rails.application.routes.routes
i = ActionDispatch::Routing::RoutesInspector.new(r)
f = ActionDispatch::Routing::ConsoleFormatter.new
i.format(f).split("\n")
end

else
require 'rails/application/route_inspector'

# returns an array of routes in Rails 3
def formatted_routes
inspector = Rails::Application::RouteInspector.new
inspector.format(Rails.application.routes.routes)
end

end

# filter and print out the routes
def routes(filter = nil)
Rails.application.reload_routes!
formatted = formatted_routes
if filter
formatted.select!{ |r| r.match(filter) }
end
puts formatted
end
end

0 comments on commit 8e9bbbe

Please sign in to comment.