Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/rubygems/basic_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def datadir
File.expand_path(File.join(gems_dir, full_name, "data", name))
end

extend Gem::Deprecate
rubygems_deprecate :datadir, :none, "4.1"

##
# Full path of the target library file.
# If the file is not in this gem, return nil.
Expand Down
8 changes: 5 additions & 3 deletions lib/rubygems/deprecate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,18 @@ def deprecate(name, repl, year, month)
# telling the user of +repl+ (unless +repl+ is :none) and the
# Rubygems version that it is planned to go away.

def rubygems_deprecate(name, replacement=:none)
def rubygems_deprecate(name, replacement=:none, version=nil)
class_eval do
old = "_deprecated_#{name}"
alias_method old, name
define_method name do |*args, &block|
klass = is_a? Module
target = klass ? "#{self}." : "#{self.class}#"
version ||= Gem::Deprecate.next_rubygems_major_version
msg = [
"NOTE: #{target}#{name} is deprecated",
replacement == :none ? " with no replacement" : "; use #{replacement} instead",
". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}",
". It will be removed in Rubygems #{version}",
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",
]
warn "#{msg.join}." unless Gem::Deprecate.skip
Expand All @@ -147,13 +148,14 @@ def rubygems_deprecate(name, replacement=:none)
end

# Deprecation method to deprecate Rubygems commands
def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version)
def rubygems_deprecate_command(version = nil)
class_eval do
define_method "deprecated?" do
true
end

define_method "deprecation_warning" do
version ||= Gem::Deprecate.next_rubygems_major_version
msg = [
"#{command} command is deprecated",
". It will be removed in Rubygems #{version}.\n",
Expand Down
7 changes: 0 additions & 7 deletions test/rubygems/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
require "shellwords"

class TestGemConfig < Gem::TestCase
def test_datadir
util_make_gems
spec = Gem::Specification.find_by_name("a")
spec.activate
assert_equal "#{spec.full_gem_path}/data/a", spec.datadir
end

def test_good_rake_path_is_escaped
path = Gem::TestCase.class_variable_get(:@@good_rake)
ruby, rake = path.shellsplit
Expand Down
29 changes: 0 additions & 29 deletions test/rubygems/test_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,35 +527,6 @@ def test_self_configuration
assert_equal expected, Gem.configuration
end

def test_self_datadir
foo = nil

Dir.chdir @tempdir do
FileUtils.mkdir_p "data"
File.open File.join("data", "foo.txt"), "w" do |fp|
fp.puts "blah"
end

foo = util_spec "foo" do |s|
s.files = %w[data/foo.txt]
end

install_gem foo
end

gem "foo"

expected = File.join @gemhome, "gems", foo.full_name, "data", "foo"

assert_equal expected, Gem::Specification.find_by_name("foo").datadir
end

def test_self_datadir_nonexistent_package
assert_raise(Gem::MissingSpecError) do
Gem::Specification.find_by_name("xyzzy").datadir
end
end

def test_self_default_exec_format
ruby_install_name "ruby" do
assert_equal "%s", Gem.default_exec_format
Expand Down