diff options
author | Andrew White <andrew.white@unboxed.co> | 2016-11-14 08:11:21 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2016-11-14 08:11:21 +0000 |
commit | b93a2571864eb858abc8b2f02f393f6751affc27 (patch) | |
tree | cc6a7ecf2e886d9d3f84ecfb681983729d1318cb | |
parent | 213f0d63a514185000502b74929ed5e6f866e48b (diff) | |
download | rails-b93a2571864eb858abc8b2f02f393f6751affc27.tar.gz rails-b93a2571864eb858abc8b2f02f393f6751affc27.tar.bz2 rails-b93a2571864eb858abc8b2f02f393f6751affc27.zip |
Remove deprecated Module.qualified_const_get/set/defined?
5 files changed, 5 insertions, 190 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index b4e54dc501..8a7bab0577 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* Remove deprecated methods `Module.qualified_const_defined?`, + `Module.qualified_const_get` and `Module.qualified_const_set` + + *Andrew White* + * Remove deprecated `:prefix` option from `number_to_human_size` *Andrew White* diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb index 57feea69a5..2930255557 100644 --- a/activesupport/lib/active_support/core_ext/module.rb +++ b/activesupport/lib/active_support/core_ext/module.rb @@ -9,4 +9,3 @@ require "active_support/core_ext/module/concerning" require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/deprecation" require "active_support/core_ext/module/remove_method" -require "active_support/core_ext/module/qualified_const" diff --git a/activesupport/lib/active_support/core_ext/module/qualified_const.rb b/activesupport/lib/active_support/core_ext/module/qualified_const.rb deleted file mode 100644 index b9814e1dbe..0000000000 --- a/activesupport/lib/active_support/core_ext/module/qualified_const.rb +++ /dev/null @@ -1,70 +0,0 @@ -require "active_support/core_ext/string/inflections" - -#-- -# Allows code reuse in the methods below without polluting Module. -#++ - -module ActiveSupport - module QualifiedConstUtils - def self.raise_if_absolute(path) - raise NameError.new("wrong constant name #$&") if path =~ /\A::[^:]+/ - end - - def self.names(path) - path.split("::") - end - end -end - -## -# Extends the API for constants to be able to deal with qualified names. Arguments -# are assumed to be relative to the receiver. -# -#-- -# Qualified names are required to be relative because we are extending existing -# methods that expect constant names, ie, relative paths of length 1. For example, -# Object.const_get('::String') raises NameError and so does qualified_const_get. -#++ -class Module - def qualified_const_defined?(path, search_parents = true) - ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - Module#qualified_const_defined? is deprecated in favour of the builtin - Module#const_defined? and will be removed in Rails 5.1. - MESSAGE - - ActiveSupport::QualifiedConstUtils.raise_if_absolute(path) - - ActiveSupport::QualifiedConstUtils.names(path).inject(self) do |mod, name| - return unless mod.const_defined?(name, search_parents) - mod.const_get(name) - end - return true - end - - def qualified_const_get(path) - ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - Module#qualified_const_get is deprecated in favour of the builtin - Module#const_get and will be removed in Rails 5.1. - MESSAGE - - ActiveSupport::QualifiedConstUtils.raise_if_absolute(path) - - ActiveSupport::QualifiedConstUtils.names(path).inject(self) do |mod, name| - mod.const_get(name) - end - end - - def qualified_const_set(path, value) - ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - Module#qualified_const_set is deprecated in favour of the builtin - Module#const_set and will be removed in Rails 5.1. - MESSAGE - - ActiveSupport::QualifiedConstUtils.raise_if_absolute(path) - - const_name = path.demodulize - mod_name = path.deconstantize - mod = mod_name.empty? ? self : const_get(mod_name) - mod.const_set(const_name, value) - end -end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index cad0d6d2e9..0146401abe 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -6,7 +6,6 @@ require "active_support/core_ext/module/aliasing" require "active_support/core_ext/module/attribute_accessors" require "active_support/core_ext/module/introspection" require "active_support/core_ext/module/anonymous" -require "active_support/core_ext/module/qualified_const" require "active_support/core_ext/object/blank" require "active_support/core_ext/kernel/reporting" require "active_support/core_ext/load_error" diff --git a/activesupport/test/core_ext/module/qualified_const_test.rb b/activesupport/test/core_ext/module/qualified_const_test.rb deleted file mode 100644 index 418bc80ab9..0000000000 --- a/activesupport/test/core_ext/module/qualified_const_test.rb +++ /dev/null @@ -1,118 +0,0 @@ -require "abstract_unit" -require "active_support/core_ext/module/qualified_const" - -module QualifiedConstTestMod - X = false - - module M - X = 1 - - class C - X = 2 - end - end - - module N - include M - end -end - -class QualifiedConstTest < ActiveSupport::TestCase - test "Object.qualified_const_defined?" do - assert_deprecated do - assert Object.qualified_const_defined?("QualifiedConstTestMod") - assert !Object.qualified_const_defined?("NonExistingQualifiedConstTestMod") - - assert Object.qualified_const_defined?("QualifiedConstTestMod::X") - assert !Object.qualified_const_defined?("QualifiedConstTestMod::Y") - - assert Object.qualified_const_defined?("QualifiedConstTestMod::M::X") - assert !Object.qualified_const_defined?("QualifiedConstTestMod::M::Y") - - if Module.method(:const_defined?).arity == 1 - assert !Object.qualified_const_defined?("QualifiedConstTestMod::N::X") - else - assert Object.qualified_const_defined?("QualifiedConstTestMod::N::X") - assert !Object.qualified_const_defined?("QualifiedConstTestMod::N::X", false) - assert Object.qualified_const_defined?("QualifiedConstTestMod::N::X", true) - end - end - end - - test "mod.qualified_const_defined?" do - assert_deprecated do - assert QualifiedConstTestMod.qualified_const_defined?("M") - assert !QualifiedConstTestMod.qualified_const_defined?("NonExistingM") - - assert QualifiedConstTestMod.qualified_const_defined?("M::X") - assert !QualifiedConstTestMod.qualified_const_defined?("M::Y") - - assert QualifiedConstTestMod.qualified_const_defined?("M::C::X") - assert !QualifiedConstTestMod.qualified_const_defined?("M::C::Y") - - if Module.method(:const_defined?).arity == 1 - assert !QualifiedConstTestMod.qualified_const_defined?("QualifiedConstTestMod::N::X") - else - assert QualifiedConstTestMod.qualified_const_defined?("N::X") - assert !QualifiedConstTestMod.qualified_const_defined?("N::X", false) - assert QualifiedConstTestMod.qualified_const_defined?("N::X", true) - end - end - end - - test "qualified_const_get" do - assert_deprecated do - assert_equal false, Object.qualified_const_get("QualifiedConstTestMod::X") - assert_equal false, QualifiedConstTestMod.qualified_const_get("X") - assert_equal 1, QualifiedConstTestMod.qualified_const_get("M::X") - assert_equal 1, QualifiedConstTestMod.qualified_const_get("N::X") - assert_equal 2, QualifiedConstTestMod.qualified_const_get("M::C::X") - - assert_raise(NameError) { QualifiedConstTestMod.qualified_const_get("M::C::Y") } - end - end - - test "qualified_const_set" do - assert_deprecated do - begin - m = Module.new - assert_equal m, Object.qualified_const_set("QualifiedConstTestMod2", m) - assert_equal m, ::QualifiedConstTestMod2 - - # We are going to assign to existing constants on purpose, so silence warnings. - silence_warnings do - assert_equal true, QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", true) - assert_equal true, QualifiedConstTestMod::X - - assert_equal 10, QualifiedConstTestMod::M.qualified_const_set("X", 10) - assert_equal 10, QualifiedConstTestMod::M::X - end - ensure - silence_warnings do - QualifiedConstTestMod.qualified_const_set("QualifiedConstTestMod::X", false) - QualifiedConstTestMod::M.qualified_const_set("X", 1) - end - end - end - end - - test "reject absolute paths" do - assert_deprecated do - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X") } - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_defined?("::X::Y") } - - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X") } - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_get("::X::Y") } - - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X", nil) } - assert_raise_with_message(NameError, "wrong constant name ::X") { Object.qualified_const_set("::X::Y", nil) } - end - end - - private - - def assert_raise_with_message(expected_exception, expected_message, &block) - exception = assert_raise(expected_exception, &block) - assert_equal expected_message, exception.message - end -end |