Class: ReaperMan::PackageList::Processor::Gem

Inherits:
ReaperMan::PackageList::Processor show all
Defined in:
lib/reaper-man/package_list/gem.rb

Instance Method Summary collapse

Methods inherited from ReaperMan::PackageList::Processor

#initialize

Methods included from Utils::Checksum

#checksum

Methods included from Utils::Process

#child_process_command, #mixlib_shellout_command, #shellout

Constructor Details

This class inherits a constructor from ReaperMan::PackageList::Processor

Instance Method Details

#add(hash, package) ⇒ Object

Add a package to the list

Parameters:

  • conf (Hash)
  • package (String)

    path to package



13
14
15
16
17
# File 'lib/reaper-man/package_list/gem.rb', line 13

def add(hash, package)
  info = extract_fields(package)
  filenames = inject_package(hash, info, package)
  filenames
end

#extract_fields(package) ⇒ Hash

Extract package metadata

Parameters:

  • package (String)

    path to package

Returns:

  • (Hash)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/reaper-man/package_list/gem.rb', line 40

def extract_fields(package)
  spec = ::Gem::Package.new(package).spec
  fields = Smash[
    spec.to_yaml_properties.map do |var_name|
      [var_name.to_s.tr('@', ''), spec.instance_variable_get(var_name)]
    end
  ]
  fields['dependencies'] = fields['dependencies'].map do |dep|
    [dep.name, dep.requirement.to_s.split(',').map(&:strip)]
  end
  fields
end

#inject_package(hash, info, package) ⇒ Array<String>

Insert package information into package list

Parameters:

  • hash (Hash)

    package list contents

  • info (Hash)

    package information

  • package (String)

    path to package file

Returns:

  • (Array<String>)

    package paths within package list contents



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/reaper-man/package_list/gem.rb', line 59

def inject_package(hash, info, package)
  package_path = File.join(
    'rubygems', 'gems', "#{info['name']}-#{info['version']}.gem"
  )
  classification = info['version'].prerelease? ? 'prerelease' : 'release'
  info['version'] = info['version'].version
  hash.deep_merge!(
    'rubygem' => {
      classification => {
        info['name'] => {
          info['version'].to_s => info.merge('package_path' => package_path)
        }
      }
    }
  )
  package_path
end

#remove(hash, package_name, version, args = {}) ⇒ Object

Remove package from the list

Parameters:

  • conf (Hash)

    configuration hash

  • package_name (String)

    name

  • version (String)


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reaper-man/package_list/gem.rb', line 24

def remove(hash, package_name, version, args={})
  deleted = false
  if(hash['rubygems'][package_name])
    if(version)
      deleted = hash['rubygems'][package_name].delete(version)
    else
      deleted = hash['rubygems'].delete(package_name)
    end
  end
  !!deleted
end