module Gem2Rpm::Helpers

Public Class Methods

check_str_on_conditions(str, conditions) click to toggle source

Compares string to the given regexp conditions

# File lib/gem2rpm/helpers.rb, line 89
def self.check_str_on_conditions(str, conditions)
  conditions.any? do |condition|
    condition.is_a?(Regexp) ? condition.match(str) : condition == str
  end
end
doc_file?(file) click to toggle source
# File lib/gem2rpm/helpers.rb, line 49
def self.doc_file?(file)
  check_str_on_conditions(file, Gem2Rpm::Configuration.instance.rule_for(:doc))
end
expand_not_equal_requirement(requirement) click to toggle source

Expands the not equal version operator '!=' into equivalent '<' and '>' pair.

# File lib/gem2rpm/helpers.rb, line 32
def self.expand_not_equal_requirement(requirement)
  return ['<', requirement.last], ['>', requirement.last]
end
expand_pessimistic_requirement(requirement) click to toggle source

Expands the pessimistic version operator '~>' into equivalent '>=' and '<' pair.

# File lib/gem2rpm/helpers.rb, line 25
def self.expand_pessimistic_requirement(requirement)
  next_version = Gem::Version.create(requirement.last).bump
  return ['=>', requirement.last], ['<', next_version]
end
expand_requirement(requirements) click to toggle source

Expands '~>' and '!=' gem requirements.

# File lib/gem2rpm/helpers.rb, line 10
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
file_entries_to_rpm(entries) click to toggle source
# File lib/gem2rpm/helpers.rb, line 44
def self.file_entries_to_rpm(entries)
  rpm_file_list = entries.map{ |e| self.file_entry_to_rpm(e) }
  rpm_file_list.join("\n")
end
file_entry_to_rpm(entry) click to toggle source
# File lib/gem2rpm/helpers.rb, line 65
def self.file_entry_to_rpm(entry)
  config = Gem2Rpm::Configuration.instance
  case true
  when doc_file?(entry)
    "#{config.macro_for(:doc)} #{config.macro_for(:instdir)}/#{entry}".strip
  when license_file?(entry)
    "#{config.macro_for(:license)} #{config.macro_for(:instdir)}/#{entry}".strip
  when ignore_file?(entry)
    "#{config.macro_for(:ignore)} #{config.macro_for(:instdir)}/#{entry}".strip
  # /lib should have its own macro
  when entry == 'lib'
    "#{config.macro_for(:libdir)}"
  else
    "#{config.macro_for(:instdir)}/#{entry}"
  end
end
ignore_file?(file) click to toggle source
# File lib/gem2rpm/helpers.rb, line 57
def self.ignore_file?(file)
  check_str_on_conditions(file, Gem2Rpm::Configuration.instance.rule_for(:ignore))
end
license_file?(file) click to toggle source
# File lib/gem2rpm/helpers.rb, line 53
def self.license_file?(file)
  check_str_on_conditions(file, Gem2Rpm::Configuration.instance.rule_for(:license))
end
misc_file?(file) click to toggle source
# File lib/gem2rpm/helpers.rb, line 61
def self.misc_file?(file)
  check_str_on_conditions(file, Gem2Rpm::Configuration.instance.rule_for(:misc))
end
requirement_versions_to_rpm(requirement) click to toggle source

Converts Gem::Requirement into array of requirements strings compatible with RPM .spec file.

# File lib/gem2rpm/helpers.rb, line 38
def self.requirement_versions_to_rpm(requirement)
  self.expand_requirement(requirement.requirements).map do |op, version|
    version == Gem::Version.new(0) ? "" : "#{op} #{version}"
  end
end
top_level_from_file_list(file_list) click to toggle source

Returns a list of top level directories and files out of an array of file_list

# File lib/gem2rpm/helpers.rb, line 84
def self.top_level_from_file_list(file_list)
  file_list.map{ |f| f.gsub!(/([^\/]*).*/,"\\1") }.uniq
end
word_wrap(text, line_width = 80) click to toggle source

Taken with modification from the ::word_wrap method in ActionPack. Text::Format does the same thing better.

# File lib/gem2rpm/helpers.rb, line 5
def self.word_wrap(text, line_width = 80)
  text.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
end