Skip to content

Commit f1152a3

Browse files
authored
Merge pull request #8900 from rubygems/deprecate-datadir
Deprecate `Gem::Specification#datadir`
2 parents 83da836 + 4925403 commit f1152a3

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

lib/rubygems/basic_specification.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def datadir
199199
File.expand_path(File.join(gems_dir, full_name, "data", name))
200200
end
201201

202+
extend Gem::Deprecate
203+
rubygems_deprecate :datadir, :none, "4.1"
204+
202205
##
203206
# Full path of the target library file.
204207
# If the file is not in this gem, return nil.

lib/rubygems/deprecate.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ def deprecate(name, repl, year, month)
126126
# telling the user of +repl+ (unless +repl+ is :none) and the
127127
# Rubygems version that it is planned to go away.
128128

129-
def rubygems_deprecate(name, replacement=:none)
129+
def rubygems_deprecate(name, replacement=:none, version=nil)
130130
class_eval do
131131
old = "_deprecated_#{name}"
132132
alias_method old, name
133133
define_method name do |*args, &block|
134134
klass = is_a? Module
135135
target = klass ? "#{self}." : "#{self.class}#"
136+
version ||= Gem::Deprecate.next_rubygems_major_version
136137
msg = [
137138
"NOTE: #{target}#{name} is deprecated",
138139
replacement == :none ? " with no replacement" : "; use #{replacement} instead",
139-
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}",
140+
". It will be removed in Rubygems #{version}",
140141
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
141142
]
142143
warn "#{msg.join}." unless Gem::Deprecate.skip
@@ -147,13 +148,14 @@ def rubygems_deprecate(name, replacement=:none)
147148
end
148149

149150
# Deprecation method to deprecate Rubygems commands
150-
def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version)
151+
def rubygems_deprecate_command(version = nil)
151152
class_eval do
152153
define_method "deprecated?" do
153154
true
154155
end
155156

156157
define_method "deprecation_warning" do
158+
version ||= Gem::Deprecate.next_rubygems_major_version
157159
msg = [
158160
"#{command} command is deprecated",
159161
". It will be removed in Rubygems #{version}.\n",

test/rubygems/test_config.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@
55
require "shellwords"
66

77
class TestGemConfig < Gem::TestCase
8-
def test_datadir
9-
util_make_gems
10-
spec = Gem::Specification.find_by_name("a")
11-
spec.activate
12-
assert_equal "#{spec.full_gem_path}/data/a", spec.datadir
13-
end
14-
158
def test_good_rake_path_is_escaped
169
path = Gem::TestCase.class_variable_get(:@@good_rake)
1710
ruby, rake = path.shellsplit

test/rubygems/test_gem.rb

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -527,35 +527,6 @@ def test_self_configuration
527527
assert_equal expected, Gem.configuration
528528
end
529529

530-
def test_self_datadir
531-
foo = nil
532-
533-
Dir.chdir @tempdir do
534-
FileUtils.mkdir_p "data"
535-
File.open File.join("data", "foo.txt"), "w" do |fp|
536-
fp.puts "blah"
537-
end
538-
539-
foo = util_spec "foo" do |s|
540-
s.files = %w[data/foo.txt]
541-
end
542-
543-
install_gem foo
544-
end
545-
546-
gem "foo"
547-
548-
expected = File.join @gemhome, "gems", foo.full_name, "data", "foo"
549-
550-
assert_equal expected, Gem::Specification.find_by_name("foo").datadir
551-
end
552-
553-
def test_self_datadir_nonexistent_package
554-
assert_raise(Gem::MissingSpecError) do
555-
Gem::Specification.find_by_name("xyzzy").datadir
556-
end
557-
end
558-
559530
def test_self_default_exec_format
560531
ruby_install_name "ruby" do
561532
assert_equal "%s", Gem.default_exec_format

0 commit comments

Comments
 (0)