Class: Gem2Rpm::RpmFileList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gem2rpm/rpm_file_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ RpmFileList

Returns a new file list created from the array of files (e.g. Gem2Rpm::Specification.files).



9
10
11
# File 'lib/gem2rpm/rpm_file_list.rb', line 9

def initialize(files)
  @items = files.map { |f| RpmFile.new(f) }
end

Instance Method Details

#doc_entriesObject

Returns new list of files suitable for -doc subpackage.



44
45
46
# File 'lib/gem2rpm/rpm_file_list.rb', line 44

def doc_entries
  self.class.new(entries.delete_if { |f| !((f.doc? && !f.license?) || f.misc? || f.test?) })
end

#eachObject

Calls the given block once for each element in self, passing that element as a parameter. Returns the array itself. If no block is given, an Enumerator is returned.



16
17
18
19
20
21
# File 'lib/gem2rpm/rpm_file_list.rb', line 16

def each
  # Return Enumerator when called withoug block.
  return to_enum(__callee__) unless block_given?

  @items.each { |item| yield item }
end

#main_entriesObject

Returns new list of files suitable for main.



39
40
41
# File 'lib/gem2rpm/rpm_file_list.rb', line 39

def main_entries
  self.class.new(entries.delete_if { |f| (f.doc? && !f.license?) || f.misc? || f.test? })
end

#rejectObject

Returns a new array containing the items in self for which the given block is not true. The ordering of non-rejected elements is maintained. If no block is given, an Enumerator is returned instead.



26
27
28
29
30
31
# File 'lib/gem2rpm/rpm_file_list.rb', line 26

def reject
  # Return Enumerator when called withoug block.
  return to_enum(__callee__) unless block_given?

  self.class.new(@items.reject { |item| yield item })
end

#to_rpmObject

Returns string with all files from the list converted into entries suitable for RPM .spec file. Thise entries should include all necessary macros depending on file categorization.



51
52
53
# File 'lib/gem2rpm/rpm_file_list.rb', line 51

def to_rpm
  entries.map(&:to_rpm).join("\n")
end

#top_level_entriesObject

Returns a list of top level directories and files, omit all subdirectories.



34
35
36
# File 'lib/gem2rpm/rpm_file_list.rb', line 34

def top_level_entries
  self.class.new(entries.map { |f| f.gsub!(/([^\/]*).*/, '\1') }.uniq)
end