Skip to content

Commit

Permalink
Small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fredwu committed Apr 8, 2013
1 parent 49b61a5 commit 9a998e1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
3 changes: 1 addition & 2 deletions lib/api_taster/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Route
cattr_accessor :metadata

class << self

def map_routes(path = "#{Rails.root}/app/api_tasters")
self.route_set = Rails.application.routes
self.supplied_params = {}
Expand All @@ -20,7 +19,7 @@ def map_routes(path = "#{Rails.root}/app/api_tasters")
normalise_routes!

begin
ApiTaster::RouteCollector.collect!(path)
ApiTaster::RouteCollector.collect(path)
Mapper.instance_eval(&self.mappings)
rescue
Route.mappings = {}
Expand Down
15 changes: 6 additions & 9 deletions lib/api_taster/route_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ class RouteCollector
cattr_accessor :routes
self.routes = []

class << self
def collect!(path)
self.routes = []
Dir["#{path}/**/*.rb"].each { |file| load(file) }
Route.mappings = Proc.new do
for route in RouteCollector.routes
instance_eval(&route)
end
end
def self.collect(path)
self.routes = []
Dir["#{path}/**/*.rb"].each { |file| load(file) }

Route.mappings = Proc.new do
RouteCollector.routes.each { |route| instance_eval(&route) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/app/api_tasters/route_collector/test2.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ApiTaster.routes do
get '/dummy_users/:id', :id => 1
get '/dummy_users/:id', :id => 42
end
2 changes: 0 additions & 2 deletions spec/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ module ApiTaster
member { map_method :patch, :update }
end
end
end

before(:all) do
Route.map_routes "#{Rails.root}/app/api_tasters/mapper"
end

Expand Down
2 changes: 1 addition & 1 deletion spec/route_collector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module ApiTaster

it "gets users" do
route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
Route.supplied_params[route[:id]].should == [{ :id => 1 }]
Route.supplied_params[route[:id]].should == [{ :id => 42 }]
end

it "posts a new user" do
Expand Down

0 comments on commit 9a998e1

Please sign in to comment.