Module: Gem2Rpm::Helpers
- Defined in:
- lib/gem2rpm/helpers.rb
Class Method Summary collapse
-
.check_str_on_conditions(str, conditions) ⇒ Object
Compares string to the given regexp conditions.
- .doc_file?(file) ⇒ Boolean
-
.expand_not_equal_requirement(requirement) ⇒ Object
Expands the not equal version operator ‘!=’ into equivalent ‘<’ and ‘>’ pair.
-
.expand_pessimistic_requirement(requirement) ⇒ Object
Expands the pessimistic version operator ‘~>’ into equivalent ‘>=’ and ‘<’ pair.
-
.expand_requirement(requirements) ⇒ Object
Expands ‘~>’ and ‘!=’ gem requirements.
- .file_entries_to_rpm(entries) ⇒ Object
- .file_entry_to_rpm(entry) ⇒ Object
- .ignore_file?(file) ⇒ Boolean
- .license_file?(file) ⇒ Boolean
- .misc_file?(file) ⇒ Boolean
-
.requirement_versions_to_rpm(requirement) ⇒ Object
Converts Gem::Requirement into array of requirements strings compatible with RPM .spec file.
-
.top_level_from_file_list(file_list) ⇒ Object
Returns a list of top level directories and files out of an array of file_list.
-
.word_wrap(text, line_width = 80) ⇒ Object
Taken with modification from the word_wrap method in ActionPack.
Class Method Details
.check_str_on_conditions(str, conditions) ⇒ Object
Compares string to the given regexp conditions
89 90 91 92 93 |
# 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) ⇒ Boolean
49 50 51 |
# 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) ⇒ Object
Expands the not equal version operator ‘!=’ into equivalent ‘<’ and ‘>’ pair.
32 33 34 |
# File 'lib/gem2rpm/helpers.rb', line 32 def self.(requirement) return ['<', requirement.last], ['>', requirement.last] end |
.expand_pessimistic_requirement(requirement) ⇒ Object
Expands the pessimistic version operator ‘~>’ into equivalent ‘>=’ and ‘<’ pair.
25 26 27 28 |
# File 'lib/gem2rpm/helpers.rb', line 25 def self.(requirement) next_version = Gem::Version.create(requirement.last).bump return ['=>', requirement.last], ['<', next_version] end |
.expand_requirement(requirements) ⇒ Object
Expands ‘~>’ and ‘!=’ gem requirements.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gem2rpm/helpers.rb', line 10 def self.(requirements) requirements.inject([]) do |output, r| output.concat case r.first when '~>' (r) when '!=' (r) else [r] end end end |
.file_entries_to_rpm(entries) ⇒ Object
44 45 46 47 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Boolean
57 58 59 |
# 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) ⇒ Boolean
53 54 55 |
# 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) ⇒ Boolean
61 62 63 |
# 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) ⇒ Object
Converts Gem::Requirement into array of requirements strings compatible with RPM .spec file.
38 39 40 41 42 |
# File 'lib/gem2rpm/helpers.rb', line 38 def self.requirement_versions_to_rpm(requirement) self.(requirement.requirements).map do |op, version| version == Gem::Version.new(0) ? "" : "#{op} #{version}" end end |
.top_level_from_file_list(file_list) ⇒ Object
Returns a list of top level directories and files out of an array of file_list
84 85 86 |
# 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) ⇒ Object
Taken with modification from the word_wrap method in ActionPack. Text::Format does the same thing better.
5 6 7 |
# 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 |