Skip to content
Browse files

Revert "Deprecate the use of non-public methods by Module#delegate"

This reverts commit aa1d1e4.

Conflicts:

	activesupport/lib/active_support/core_ext/module/delegation.rb
	activesupport/test/core_ext/module_test.rb
  • Loading branch information...
1 parent dbdb230 commit b0d95487ed6ffeeedc217be5d6cfea6a8f15b2b8 @jonleighton jonleighton committed Aug 19, 2011
View
2 activesupport/CHANGELOG
@@ -1,7 +1,5 @@
*Rails 3.1.0 (unreleased)*
-* Using Module#delegate to delegate to non-public methods is deprecated [Jon Leighton]
-
* ActiveSupport::Dependencies now raises NameError if it finds an existing constant in load_missing_constant. This better reflects the nature of the error which is usually caused by calling constantize on a nested constant. [Andrew White]
* Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
View
38 activesupport/lib/active_support/core_ext/module/delegation.rb
@@ -1,6 +1,4 @@
require "active_support/core_ext/module/remove_method"
-require 'active_support/core_ext/kernel/singleton_class'
-require 'active_support/deprecation'
class Module
# Provides a delegate class method to easily expose contained objects' methods
@@ -128,32 +126,16 @@ def delegate(*methods)
%(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
end
- module_eval(<<-EOS, file, line - 4)
- def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
- to = #{to} # to = client
- #
- begin # begin
- result = to.__send__(#{method.inspect}, *args, &block) # result = to.__send__(:name, *args, &block)
- rescue NoMethodError # rescue NoMethodError
- if to.nil? # if to.nil?
- #{on_nil} # return # depends on :allow_nil
- else # else
- raise # raise
- end # end
- end # end
- #
- klass = to.singleton_methods.any? ? to.singleton_class : to.class # klass = to.singleton_methods.any? ? to.singleton_class : to.class
- unless klass.public_method_defined?(#{method.inspect}) # unless klass.public_method_defined?(:name)
- ActiveSupport::Deprecation.warn( # ActiveSupport::Deprecation.warn(
- "Using Module#delegate to delegate to non-public methods is " + # "..." +
- "deprecated. Please declare your methods as public if they " + # "..." +
- "are going to accessed from other classes.", # "...",
- [#{"#{file}:#{line}".inspect}] # ["app/models/firm.rb:16"]
- ) # )
- end # end
- #
- result # result
- end # end
+ module_eval(<<-EOS, file, line - 1)
+ def #{prefix}#{method}(*args, &block) # def customer_name(*args, &block)
+ #{to}.__send__(#{method.inspect}, *args, &block) # client.__send__(:name, *args, &block)
+ rescue NoMethodError # rescue NoMethodError
+ if #{to}.nil? # if client.nil?
+ #{on_nil} # return # depends on :allow_nil
+ else # else
+ raise # raise
+ end # end
+ end # end
EOS
end
end
View
31 activesupport/test/core_ext/module_test.rb
@@ -1,6 +1,5 @@
require 'abstract_unit'
require 'active_support/core_ext/module'
-require 'active_support/testing/deprecation'
module One
Constant1 = "Hello World"
@@ -27,22 +26,10 @@ class Cd
end
end
-Somewhere = Struct.new(:street, :city) do
- protected
-
- def protected_method
- "protected"
- end
-
- private
-
- def private_method
- "private"
- end
-end
+Somewhere = Struct.new(:street, :city)
class Someone < Struct.new(:name, :place)
- delegate :street, :city, :to_f, :protected_method, :private_method, :to => :place
+ delegate :street, :city, :to_f, :to => :place
delegate :upcase, :to => "place.city"
FAILED_DELEGATE_LINE = __LINE__ + 1
@@ -76,8 +63,6 @@ def initialize(first, last)
end
class ModuleTest < Test::Unit::TestCase
- include ActiveSupport::Testing::Deprecation
-
def setup
@david = Someone.new("David", Somewhere.new("Paulina", "Chicago"))
end
@@ -87,18 +72,6 @@ def test_delegation_to_methods
assert_equal "Chicago", @david.city
end
- def test_delegation_to_protected_method
- assert_deprecated do
- assert_equal "protected", @david.protected_method
- end
- end
-
- def test_delegation_to_private_method
- assert_deprecated do
- assert_equal "private", @david.private_method
- end
- end
-
def test_delegation_down_hierarchy
assert_equal "CHICAGO", @david.upcase
end

0 comments on commit b0d9548

Please sign in to comment.
Something went wrong with that request. Please try again.