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 CHANGED
@@ -1,5 +1,6 @@
1
1
  .DS_Store
2
2
  ._*
3
+ .tags
3
4
  .bundle/
4
5
  coverage/
5
6
  log/*.log
@@ -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.route_set = Rails.application.routes
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
@@ -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 routes
10
- _routes = []
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
- _routes << normalise_route(rack_route, i+=1)
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
- _routes << normalise_route(route, i+=1)
40
+ self.routes << normalise_route(route, i+=1)
30
41
  end
31
-
32
- _routes
33
42
  end
34
43
 
35
44
  def grouped_routes
@@ -1,3 +1,3 @@
1
1
  module ApiTaster
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
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
- Route.route_set = routes
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.routes }.to raise_exception(ApiTaster::Exception)
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.2
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: -2192023684559152796
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: -2192023684559152796
366
+ hash: 261485977407243398
367
367
  requirements: []
368
368
  rubyforge_project:
369
369
  rubygems_version: 1.8.24