grep_routes 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,9 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grep_routes (0.0.0)
5
- actionpack (~> 3.1.3)
6
- activesupport (~> 3.1.3)
4
+ grep_routes (0.0.4)
7
5
 
8
6
  GEM
9
7
  remote: http://rubygems.org/
@@ -48,5 +46,7 @@ PLATFORMS
48
46
  ruby
49
47
 
50
48
  DEPENDENCIES
49
+ actionpack (~> 3.1)
50
+ activesupport (~> 3.1)
51
51
  grep_routes!
52
52
  minitest (~> 2.11.2)
data/README.md CHANGED
@@ -2,7 +2,9 @@ Grep Routes
2
2
  ===========
3
3
  Running `rake routes` is super slow and a waste of time.
4
4
 
5
- `grep_routes` is similar to `rake routes | grep someroute` but way faster.
5
+ `grep_routes` is similar to `rake routes | grep someroute` but way faster. My SuperScientificBenchmarks™ indicate 10x speed improvement over `rake routes` on big Rails projects to 3x on a fresh Rails 3.2 app, ymmv.
6
+
7
+ **Note: This only works on Rails 3.1 and 3.2.**
6
8
 
7
9
  Install
8
10
  -------
@@ -32,7 +34,3 @@ Please use [Github Issues](https://github.com/ubermajestix/grep_routes/issues) t
32
34
  Contributing
33
35
  ------------
34
36
  Fork, code, send pull request.
35
-
36
- Thanks
37
- ------
38
- Thanks to [@nateabbott](https://twitter.com/nateabbott) for the inspiration and [Everlater](http://www.everlater.com/professional) for allowing me to contribute to open source on their time.
data/bin/grep_routes CHANGED
File without changes
data/grep_routes.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "grep_routes"
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
  s.authors = ["Tyler Montgomery"]
7
7
  s.email = ["tyler.a.montgomery@gmail.com"]
8
8
  s.homepage = "http://github.com/ubermajestix/grep_routes"
@@ -14,8 +14,16 @@ Gem::Specification.new do |s|
14
14
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
15
  s.require_paths = ["lib"]
16
16
 
17
- s.add_dependency "activesupport" , "~> 3.1"
18
- s.add_dependency "actionpack" , "~> 3.1"
19
-
20
- s.add_development_dependency "minitest", "~> 2.11.2"
17
+ # Get the latest 3 release of activesupport and actionpack for development.
18
+ # Adjust the version here to test backwards compatibility.
19
+ # I use bundler and rvm with a gemset so if I change the versions I:
20
+ #
21
+ # rvm gemset empty
22
+ # bundle install
23
+ #
24
+ # Is there a better way to do this?
25
+ #
26
+ s.add_development_dependency "activesupport" , "~> 3.1"
27
+ s.add_development_dependency "actionpack" , "~> 3.1"
28
+ s.add_development_dependency "minitest" , "~> 2.11.2"
21
29
  end
data/lib/grep_routes.rb CHANGED
@@ -1,6 +1,23 @@
1
+ # See if the user has the 3.2 or 3.1 version of active_support.
2
+ # If not, blow up.
3
+ begin
4
+ gem 'activesupport', '>= 3.1.0', '< 3.3.0'
5
+ rescue LoadError => e
6
+ puts "You do not have activesupport ~> 3.1 installed.\nThis gem does not work with Rails 2 or 3.0"
7
+ exit 1
8
+ end
1
9
  require 'active_support'
2
10
  require 'active_support/core_ext/hash/reverse_merge'
3
11
  require 'active_support/core_ext/enumerable'
12
+
13
+ # See if the user has the 3.2 or 3.1 version of actionpack for action_dispatch.
14
+ # If not, blow up.
15
+ begin
16
+ gem 'actionpack', '>= 3.1.0', '< 3.3.0'
17
+ rescue LoadError
18
+ puts "You do not have actionpack ~> 3.1 installed.\nThis gem does not work with Rails 2 or 3.0"
19
+ exit 1
20
+ end
4
21
  require 'action_dispatch'
5
22
 
6
23
  class GrepRoutes
@@ -88,13 +105,47 @@ class GrepRoutes
88
105
  return @routes if @routes
89
106
 
90
107
  @routes = route_set.routes.collect do |route|
91
- reqs = route.requirements.dup
92
- reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
93
- reqs = reqs.empty? ? "" : reqs.inspect
94
- {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs}
108
+ # reqs = route.requirements.dup
109
+ # reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
110
+ # reqs = reqs.empty? ? "" : reqs.inspect
111
+ # puts "="*45
112
+ # puts route.path.inspect
113
+ # puts route.path.spec.inspect
114
+ # puts "="*45
115
+ # {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path.to_s, :reqs => reqs}
116
+
117
+ route_reqs = route.requirements
118
+
119
+
120
+ controller = route_reqs[:controller] || ':controller'
121
+ action = route_reqs[:action] || ':action'
122
+
123
+ # rack_app = discover_rack_app(route.app)
124
+ # endpoint = rack_app ? rack_app.inspect : "#{controller}##{action}"
125
+ endpoint = "#{controller}##{action}"
126
+ constraints = route_reqs.except(:controller, :action)
127
+
128
+ reqs = endpoint
129
+ reqs += " #{constraints.inspect}" unless constraints.empty?
130
+
131
+ if route.verb.respond_to?(:source)
132
+ verb = route.verb.source.gsub(/[$^]/, '')
133
+ else
134
+ verb = route.verb
135
+ end
136
+
137
+ if route.path.respond_to?(:spec)
138
+ path = route.path.spec.to_s
139
+ else
140
+ path = route.path
141
+ end
142
+
143
+ # collect_engine_routes(reqs, rack_app)
144
+
145
+ {:name => route.name.to_s, :verb => verb, :path => path, :reqs => reqs }
95
146
  end
96
147
  # Skip the route if it's internal info route
97
- @routes.reject! { |r| r[:path] =~ /\/rails\/info\/properties|^\/assets/ }
148
+ @routes. reject! { |r| r[:path] =~ /\/rails\/info\/properties|^\/assets/ }
98
149
  return @routes
99
150
  end
100
151
 
@@ -113,6 +164,7 @@ class GrepRoutes
113
164
  # This formats the route as an Array of Strings.
114
165
  # This is stolen from the Rail's routes rake task.
115
166
  def formatted_routes
167
+ puts routes.first.inspect
116
168
  name_width = routes.map{ |r| r[:name].length }.max
117
169
  verb_width = routes.map{ |r| r[:verb].length }.max
118
170
  path_width = routes.map{ |r| r[:path].length }.max
@@ -19,7 +19,7 @@ describe GrepRoutes do
19
19
 
20
20
  it "there should be routes after we eval the routes file" do
21
21
  subject.eval_routes
22
- subject.route_set.routes.wont_be_empty
22
+ subject.route_set.routes.length.must_be :>, 1
23
23
  end
24
24
 
25
25
  it "should filter routes" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grep_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,29 +13,29 @@ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70238163830600 !ruby/object:Gem::Requirement
16
+ requirement: &70135441232700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.1'
22
- type: :runtime
22
+ type: :development
23
23
  prerelease: false
24
- version_requirements: *70238163830600
24
+ version_requirements: *70135441232700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: actionpack
27
- requirement: &70238163830120 !ruby/object:Gem::Requirement
27
+ requirement: &70135441232040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.1'
33
- type: :runtime
33
+ type: :development
34
34
  prerelease: false
35
- version_requirements: *70238163830120
35
+ version_requirements: *70135441232040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &70238163829600 !ruby/object:Gem::Requirement
38
+ requirement: &70135441231060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 2.11.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70238163829600
46
+ version_requirements: *70135441231060
47
47
  description: Greppin in ur routes
48
48
  email:
49
49
  - tyler.a.montgomery@gmail.com