Deprecate InstanceMethods namespace handling in ActiveSupport::Concern.
This avoids the unnecessary "yo dawg, I heard you like include, so I put a module that includes your module when it is included" approach when building extensions.
This commit is contained in:
parent
f312e2142b
commit
401393b656
|
@ -4,17 +4,12 @@ module ActiveSupport
|
|||
# module M
|
||||
# def self.included(base)
|
||||
# base.extend ClassMethods
|
||||
# base.send(:include, InstanceMethods)
|
||||
# scope :disabled, where(:disabled => true)
|
||||
# end
|
||||
#
|
||||
# module ClassMethods
|
||||
# ...
|
||||
# end
|
||||
#
|
||||
# module InstanceMethods
|
||||
# ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# By using <tt>ActiveSupport::Concern</tt> the above module could instead be written as:
|
||||
|
@ -31,10 +26,6 @@ module ActiveSupport
|
|||
# module ClassMethods
|
||||
# ...
|
||||
# end
|
||||
#
|
||||
# module InstanceMethods
|
||||
# ...
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Moreover, it gracefully handles module dependencies. Given a +Foo+ module and a +Bar+
|
||||
|
@ -118,7 +109,11 @@ module ActiveSupport
|
|||
@_dependencies.each { |dep| base.send(:include, dep) }
|
||||
super
|
||||
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
|
||||
base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
|
||||
if const_defined?("InstanceMethods")
|
||||
base.send :include, const_get("InstanceMethods")
|
||||
ActiveSupport::Deprecation.warn "The InstanceMethods module inside ActiveSupport::Concern will be " \
|
||||
"no longer included automatically. Please define instance methods directly in #{base} instead.", caller
|
||||
end
|
||||
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,9 +19,6 @@ class ConcernTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
end
|
||||
|
||||
included do
|
||||
self.included_ran = true
|
||||
end
|
||||
|
@ -74,7 +71,7 @@ class ConcernTest < Test::Unit::TestCase
|
|||
def test_instance_methods_are_included
|
||||
@klass.send(:include, Baz)
|
||||
assert_equal "baz", @klass.new.baz
|
||||
assert @klass.included_modules.include?(ConcernTest::Baz::InstanceMethods)
|
||||
assert @klass.included_modules.include?(ConcernTest::Baz)
|
||||
end
|
||||
|
||||
def test_included_block_is_ran
|
||||
|
@ -92,6 +89,6 @@ class ConcernTest < Test::Unit::TestCase
|
|||
|
||||
def test_dependencies_with_multiple_modules
|
||||
@klass.send(:include, Foo)
|
||||
assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz::InstanceMethods, ConcernTest::Baz], @klass.included_modules[0..3]
|
||||
assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..2]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue