Extract composition of dependecy strings into helper.

This commit is contained in:
Vít Ondruch 2019-01-24 10:36:55 +01:00
parent d66ece5f5d
commit bb1cbacab5

View File

@ -38,31 +38,32 @@ module RubyGemsReq
version == Gem::Version.new(0) ? "" : " #{op} #{version}" version == Gem::Version.new(0) ? "" : " #{op} #{version}"
end end
end end
# Compose dependency together with its requirements in RPM rich dependency
# string.
def self.compose_dependency_string(name, requirements)
dependency_strings = requirements.map { |requirement| name + requirement }
dependency_string = dependency_strings.join(' with ')
dependency_string.prepend('(').concat(')') if dependency_strings.length > 1
dependency_string
end
end end
# Report RubyGems dependency, versioned if required. # Report RubyGems dependency, versioned if required.
def self.rubygems_dependency(specification) def self.rubygems_dependency(specification)
dependency_strings = Helpers::requirement_versions_to_rpm(specification.required_rubygems_version).map do |requirement| dependency_name = "ruby(rubygems)"
requirement_string = "ruby(rubygems)" requirements = Helpers::requirement_versions_to_rpm(specification.required_rubygems_version)
requirement_string += " #{requirement}" if requirement&.length > 0
requirement_string puts Helpers::compose_dependency_string(dependency_name, requirements)
end
dependency_string = dependency_strings.join(' with ')
dependency_string.prepend('(').concat(')') if dependency_strings.length > 1
puts dependency_string
end end
# Report all gem dependencies including their version. # Report all gem dependencies including their version.
def self.gem_depenencies(specification) def self.gem_depenencies(specification)
specification.runtime_dependencies.each do |dependency| specification.runtime_dependencies.each do |dependency|
dependency_strings = Helpers::requirement_versions_to_rpm(dependency.requirement).map do |requirement| dependency_name = "rubygem(#{dependency.name})"
requirement_string = "rubygem(#{dependency.name})" requirements = Helpers::requirement_versions_to_rpm(dependency.requirement)
requirement_string += " #{requirement}" if requirement&.length > 0
requirement_string puts Helpers::compose_dependency_string(dependency_name, requirements)
end
dependency_string = dependency_strings.join(' with ')
dependency_string.prepend('(').concat(')') if dependency_strings.length > 1
puts dependency_string
end end
end end