Skip to content

Commit

Permalink
[rubygems/rubygems] Simplify #to_ruby code
Browse files Browse the repository at this point in the history
Separate #add_runtime_dependency and #add_development_dependency
availability condition from #specification_version availability,
which is not related to directly.
Also check if the former method is available, instead of comparing
the version.

rubygems/rubygems@5cccc2b836
  • Loading branch information
nobu authored and hsbt committed Jul 30, 2019
1 parent 5947ea3 commit a2f0331
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
14 changes: 3 additions & 11 deletions lib/rubygems/specification.rb
Expand Up @@ -2476,25 +2476,17 @@ def to_ruby
result << nil
result << " if s.respond_to? :specification_version then"
result << " s.specification_version = #{specification_version}"
result << " end"
result << nil

result << " if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
result << " if s.respond_to? :add_runtime_dependency then"

dependencies.each do |dep|
req = dep.requirements_list.inspect
dep.instance_variable_set :@type, :runtime if dep.type.nil? # HACK
result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>.freeze, #{req})"
result << " s.add_#{dep.type}_dependency(%q<#{dep.name}>.freeze, #{req})"
end

result << " else"

dependencies.each do |dep|
version_reqs_param = dep.requirements_list.inspect
result << " s.add_dependency(%q<#{dep.name}>.freeze, #{version_reqs_param})"
end

result << ' end'

result << " else"
dependencies.each do |dep|
version_reqs_param = dep.requirements_list.inspect
Expand Down
30 changes: 11 additions & 19 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -2428,12 +2428,10 @@ def test_to_ruby
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
end
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
Expand Down Expand Up @@ -2478,12 +2476,10 @@ def test_to_ruby_for_cache
if s.respond_to? :specification_version then
s.specification_version = #{Gem::Specification::CURRENT_SPECIFICATION_VERSION}
end
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<b>.freeze, [\"= 1\"])
else
s.add_dependency(%q<b>.freeze, [\"= 1\"])
end
Expand Down Expand Up @@ -2539,16 +2535,12 @@ def test_to_ruby_fancy
if s.respond_to? :specification_version then
s.specification_version = 4
end
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>.freeze, [\"> 0.4\", \"<= 0.6\"])
else
s.add_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
s.add_dependency(%q<pqa>.freeze, [\"> 0.4\", \"<= 0.6\"])
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_runtime_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
s.add_runtime_dependency(%q<pqa>.freeze, [\"> 0.4\", \"<= 0.6\"])
else
s.add_dependency(%q<rake>.freeze, [\"> 0.4\"])
s.add_dependency(%q<jabber4r>.freeze, [\"> 0.0.0\"])
Expand Down

0 comments on commit a2f0331

Please sign in to comment.