api_taster 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/app/controllers/api_taster/routes_controller.rb +8 -0
- data/lib/api_taster.rb +1 -5
- data/lib/api_taster/route.rb +16 -7
- data/lib/api_taster/version.rb +1 -1
- data/spec/mapper_spec.rb +3 -0
- data/spec/route_spec.rb +4 -2
- metadata +3 -3
data/.gitignore
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module ApiTaster
|
2
2
|
class RoutesController < ApplicationController
|
3
|
+
before_filter :map_routes
|
4
|
+
|
3
5
|
def index
|
4
6
|
@routes = Route.grouped_routes
|
5
7
|
@has_missing_definitions = Route.missing_definitions.present?
|
@@ -18,5 +20,11 @@ module ApiTaster
|
|
18
20
|
def obsolete_definitions
|
19
21
|
@obsolete_definitions = Route.obsolete_definitions
|
20
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def map_routes
|
27
|
+
Route.map_routes
|
28
|
+
end
|
21
29
|
end
|
22
30
|
end
|
data/lib/api_taster.rb
CHANGED
@@ -6,11 +6,7 @@ require 'api_taster/form_builder'
|
|
6
6
|
|
7
7
|
module ApiTaster
|
8
8
|
def self.routes(&block)
|
9
|
-
Route.
|
10
|
-
Route.inputs = {}
|
11
|
-
Route.obsolete_definitions = []
|
12
|
-
|
13
|
-
Mapper.instance_eval(&block)
|
9
|
+
Route.mappings = Proc.new { block }
|
14
10
|
end
|
15
11
|
|
16
12
|
class Exception < ::Exception; end
|
data/lib/api_taster/route.rb
CHANGED
@@ -1,13 +1,24 @@
|
|
1
1
|
module ApiTaster
|
2
2
|
class Route
|
3
3
|
cattr_accessor :route_set
|
4
|
+
cattr_accessor :routes
|
5
|
+
cattr_accessor :mappings
|
4
6
|
cattr_accessor :inputs
|
5
|
-
cattr_accessor :missing_definitions
|
6
7
|
cattr_accessor :obsolete_definitions
|
7
8
|
|
8
9
|
class << self
|
9
|
-
def
|
10
|
-
|
10
|
+
def map_routes
|
11
|
+
self.route_set = Rails.application.routes
|
12
|
+
self.inputs = {}
|
13
|
+
self.obsolete_definitions = []
|
14
|
+
|
15
|
+
normalise_routes!
|
16
|
+
|
17
|
+
Mapper.instance_eval(&self.mappings.call)
|
18
|
+
end
|
19
|
+
|
20
|
+
def normalise_routes!
|
21
|
+
self.routes = []
|
11
22
|
i = -1
|
12
23
|
|
13
24
|
unless route_set.respond_to?(:routes)
|
@@ -20,16 +31,14 @@ module ApiTaster
|
|
20
31
|
|
21
32
|
if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes)
|
22
33
|
rack_app.routes.routes.each do |rack_route|
|
23
|
-
|
34
|
+
self.routes << normalise_route(rack_route, i+=1)
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
27
38
|
next if route.verb.source.empty?
|
28
39
|
|
29
|
-
|
40
|
+
self.routes << normalise_route(route, i+=1)
|
30
41
|
end
|
31
|
-
|
32
|
-
_routes
|
33
42
|
end
|
34
43
|
|
35
44
|
def grouped_routes
|
data/lib/api_taster/version.rb
CHANGED
data/spec/mapper_spec.rb
CHANGED
@@ -14,6 +14,7 @@ module ApiTaster
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Route.route_set = routes
|
17
|
+
Route.map_routes
|
17
18
|
end
|
18
19
|
|
19
20
|
it "records obsolete definitions" do
|
@@ -31,6 +32,8 @@ module ApiTaster
|
|
31
32
|
put '/dummy_users/:id', :id => 2
|
32
33
|
delete '/dummy_users/:id', :id => 3
|
33
34
|
end
|
35
|
+
|
36
|
+
Route.map_routes
|
34
37
|
end
|
35
38
|
|
36
39
|
it "gets users" do
|
data/spec/route_spec.rb
CHANGED
@@ -26,7 +26,8 @@ module ApiTaster
|
|
26
26
|
mount proc {} => '/rack_app'
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
Rails.application.stub(:routes).and_return(routes)
|
30
|
+
Route.map_routes
|
30
31
|
end
|
31
32
|
|
32
33
|
it "#routes" do
|
@@ -36,7 +37,7 @@ module ApiTaster
|
|
36
37
|
context "undefined ApiTaster.routes" do
|
37
38
|
it "errors out" do
|
38
39
|
Route.route_set = nil
|
39
|
-
expect { Route.
|
40
|
+
expect { Route.normalise_routes! }.to raise_exception(ApiTaster::Exception)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -88,6 +89,7 @@ module ApiTaster
|
|
88
89
|
ApiTaster.routes do
|
89
90
|
# nothing
|
90
91
|
end
|
92
|
+
Route.map_routes
|
91
93
|
|
92
94
|
Route.missing_definitions.first[:path].should == '/awesome_route'
|
93
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_taster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -354,7 +354,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
354
354
|
version: '0'
|
355
355
|
segments:
|
356
356
|
- 0
|
357
|
-
hash:
|
357
|
+
hash: 261485977407243398
|
358
358
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
359
359
|
none: false
|
360
360
|
requirements:
|
@@ -363,7 +363,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
363
363
|
version: '0'
|
364
364
|
segments:
|
365
365
|
- 0
|
366
|
-
hash:
|
366
|
+
hash: 261485977407243398
|
367
367
|
requirements: []
|
368
368
|
rubyforge_project:
|
369
369
|
rubygems_version: 1.8.24
|