Module: Polisher::GemFiles

Included in:
Gem
Defined in:
lib/polisher/gem/files.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

IGNORE_FILES =

Common files shipped in gems that we should ignore

['.gemtest', '.gitignore', '.travis.yml',
/.*.gemspec/, /Gemfile.*/, 'Rakefile',
/rspec.*/, '.yardopts', '.rvmrc']
RUNTIME_FILES =

Critical runtime files that are necessary for the gem to run

[/\Alib.*/, /\Abin.*/, /\Aapp.*/, /\Avendor.*/]
LICENSE_FILES =

License files

[/\/?MIT/, /\/?GPLv[0-9]+/, /\/?.*LICEN(C|S)E/, /\/?COPYING/]
DOC_FILES =

Common files shipped in gems considered doc

[/\/?CHANGELOG.*/i, /\/?CONTRIBUTING.*/i, /\/?CONTRIBUTORS.*/i,
/\/?README.*/i, /\/?History.*/i, /\/?Release.*/i, /\/?doc(\/.*)?/]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



27
28
29
# File 'lib/polisher/gem/files.rb', line 27

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#each_file(&bl) ⇒ Object

Iterate over each file in gem invoking block with path



88
89
90
91
92
93
94
95
96
# File 'lib/polisher/gem/files.rb', line 88

def each_file(&bl)
  unpack do |dir|
    Pathname.new(dir).find do |path|
      next if path.to_s == dir.to_s
      pathstr = path.to_s.gsub("#{dir}/", '')
      bl.call pathstr unless pathstr.blank?
    end
  end
end

#file_pathsArray<String>

Retrieve the list of paths to files in the gem

Returns:

  • (Array<String>)

    list of files in the gem



101
102
103
104
105
106
107
108
109
# File 'lib/polisher/gem/files.rb', line 101

def file_paths
  @file_paths ||= begin
    files = []
    each_file do |path|
      files << path
    end
    files
  end
end

#has_file_satisfied_by?(spec_file) ⇒ Boolean

Return bool indicating if spec file satisfies any file in gem

Returns:

  • (Boolean)


62
63
64
# File 'lib/polisher/gem/files.rb', line 62

def has_file_satisfied_by?(spec_file)
  file_paths.any? { |gem_file| RPM::Spec.file_satisfies?(spec_file, gem_file) }
end

#unpack(&bl) ⇒ Object

Unpack files & return unpacked directory

If block is specified, it will be invoked with directory after which directory will be removed



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/polisher/gem/files.rb', line 70

def unpack(&bl)
  dir = nil
  pkg = ::Gem::Installer.new gem_path, :unpack => true

  if bl
    Dir.mktmpdir do |tmpdir|
      pkg.unpack tmpdir
      bl.call tmpdir
    end
  else
    dir = Dir.mktmpdir
    pkg.unpack dir
  end

  dir
end