1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Allow Module#depends_on to accept multiple modules

This commit is contained in:
Pratik Naik 2009-05-21 03:04:17 +02:00
parent e21d1614bb
commit 5a03645762
3 changed files with 18 additions and 8 deletions

View file

@ -4,10 +4,7 @@ module ActionController #:nodoc:
# TODO : Remove the defined? check when new base is the main base
if defined?(ActionController::Http)
depends_on AbstractController::Callbacks
depends_on Session
depends_on Flash
depends_on Renderer
depends_on AbstractController::Callbacks, Session, Flash, Renderer
end
# This module provides a class-level method for specifying that certain

View file

@ -16,10 +16,12 @@ module ActiveSupport
end
end
def depends_on(mod)
return if self < mod
def depends_on(*mods)
mods.each do |mod|
next if self < mod
@_dependencies ||= []
@_dependencies << mod
end
end
end
end

View file

@ -42,6 +42,12 @@ class DependencyModuleTest < Test::Unit::TestCase
end
end
module Foo
extend ActiveSupport::DependencyModule
depends_on Bar, Baz
end
def setup
@klass = Class.new
end
@ -74,4 +80,9 @@ class DependencyModuleTest < Test::Unit::TestCase
assert_equal "baz", @klass.baz
assert_equal [DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..1]
end
def test_depends_on_with_multiple_modules
@klass.send(:include, Foo)
assert_equal [DependencyModuleTest::Foo, DependencyModuleTest::Bar, DependencyModuleTest::Baz], @klass.included_modules[0..2]
end
end