Sha256: c79c4da69fe12ea62700b055f4eaea2a3f9da87ba631e38c994f63a4af96f2e1
Contents?: true
Size: 1.66 KB
Versions: 3
Compression:
Stored size: 1.66 KB
Contents
module Gem2Rpm module Helpers # Taken with modification from the word_wrap method in ActionPack. # Text::Format does the same thing better. def self.word_wrap(text, line_width = 80) text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip end # Expands '~>' and '!=' gem requirements. def self.expand_requirement(requirements) requirements.inject([]) do |output, r| output.concat case r.first when '~>' expand_pessimistic_requirement(r) when '!=' expand_not_equal_requirement(r) else [r] end end end # Expands the pessimistic version operator '~>' into equivalent '>=' and # '<' pair. def self.expand_pessimistic_requirement(requirement) next_version = Gem::Version.create(requirement.last).bump return ['>=', requirement.last], ['<', next_version] end # Expands the not equal version operator '!=' into equivalent '<' and # '>' pair. def self.expand_not_equal_requirement(requirement) return ['<', requirement.last], ['>', requirement.last] end # Converts Gem::Requirement into array of requirements strings compatible # with RPM .spec file. def self.requirement_versions_to_rpm(requirement) expand_requirement(requirement.requirements).map do |op, version| version == Gem::Version.new(0) ? "" : "#{op} #{version}" end end # Compares string to the given regexp conditions def self.check_str_on_conditions(str, conditions) conditions.any? do |condition| condition.is_a?(Regexp) ? condition.match(str) : condition == str end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
gem2rpm-1.0.2 | lib/gem2rpm/helpers.rb |
gem2rpm-1.0.1 | lib/gem2rpm/helpers.rb |
gem2rpm-1.0.0 | lib/gem2rpm/helpers.rb |