Permalink
Browse files

Move engine accessor to top level module.

SimpleRouter.engine
  • Loading branch information...
1 parent 333cb7a commit 8bdfbe985b0a765962547c89bfa4d2e8150e6415 @mynyml committed May 19, 2009
Showing with 29 additions and 19 deletions.
  1. +5 −0 lib/simple_router.rb
  2. +1 −8 lib/simple_router/routes.rb
  3. +0 −11 test/test_routes.rb
  4. +23 −0 test/test_simple_router.rb
View
@@ -1,4 +1,9 @@
module SimpleRouter
+ class << self
+ attr_accessor :engine
+ def engine() @engine || Engines::SimpleEngine end
+ end
+
autoload :DSL, 'simple_router/dsl'
autoload :Routes, 'simple_router/routes'
@@ -1,13 +1,6 @@
module SimpleRouter
class Routes < Array
- # routing engine
- attr_accessor :engine
-
- def engine
- @engine || Engines::SimpleEngine
- end
-
def add(*args, &action)
self << Route.new(*args, &action)
end
@@ -21,7 +14,7 @@ def match(verb, path)
routes = self.select {|route| route.verb == verb }
paths = routes.map {|route| route.path }
- path, vars = self.engine.match(path, paths)
+ path, vars = SimpleRouter.engine.match(path, paths)
return none if path.nil?
route = routes.detect {|route| route.path == path }
View
@@ -39,17 +39,6 @@ def setup
@routes.match('GET', '/bar').first.path.should be('/bar')
@routes.match(' GET ','/bar').first.path.should be('/bar')
end
-
- ## engine
-
- test "default engine" do
- @routes.engine.name.split('::').last.should be('SimpleEngine')
- end
-
- test "custom engine" do
- @routes.engine = ::Object
- @routes.engine.name.should be('Object')
- end
end
class RouteTest < Test::Unit::TestCase
View
@@ -0,0 +1,23 @@
+require 'test/test_helper'
+
+class App
+ include SimpleRouter::DSL
+end
+
+class SimpleRouterTest < Test::Unit::TestCase
+
+ def setup
+ SimpleRouter.engine = nil
+ end
+
+ ## engine
+
+ test "default engine" do
+ SimpleRouter.engine.name.split('::').last.should be('SimpleEngine')
+ end
+
+ test "custom engine" do
+ SimpleRouter.engine = ::Object
+ SimpleRouter.engine.name.should be('Object')
+ end
+end

0 comments on commit 8bdfbe9

Please sign in to comment.