Skip to content

Commit

Permalink
Move engine accessor to top level module.
Browse files Browse the repository at this point in the history
SimpleRouter.engine
  • Loading branch information
mynyml committed May 19, 2009
1 parent 333cb7a commit 8bdfbe9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lib/simple_router.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
9 changes: 1 addition & 8 deletions lib/simple_router/routes.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 }
Expand Down
11 changes: 0 additions & 11 deletions test/test_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/test_simple_router.rb
Original file line number Diff line number Diff line change
@@ -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.