Sha256: a33d803d1f9f29ad9c566cdbc56b230369b711b60e014e972fa1353022465e4f

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

Puppet::Type.type(:rbenvgem).provide :default do
  desc "Maintains gems inside an RBenv setup"

  commands :su => 'su'

  def install
    args = ['install', '--no-rdoc', '--no-ri']
    args << "-v#{resource[:ensure]}" if !resource[:ensure].kind_of?(Symbol)
    args << gem_name

    output = gem(*args)
    fail "Could not install: #{output.chomp}" if output.include?('ERROR')
  end

  def uninstall
    gem 'uninstall', '-aIx', gem_name
  end

  def latest
    @latest ||= list(:remote)
  end

  def current
    list
  end

  private
    def gem_name
      resource[:gemname]
    end

    def gem(*args)
      exe =  "RBENV_VERSION=#{resource[:ruby]} " + resource[:rbenv] + '/bin/gem'
      su('-', resource[:user], '-c', [exe, *args].join(' '))
    end

    def list(where = :local)
      args = ['list', where == :remote ? '--remote' : '--local', "#{gem_name}$"]

      gem(*args).lines.map do |line|
        line =~ /^(?:\S+)\s+\((.+)\)/

        return nil unless $1

        # Fetch the version number
        ver = $1.split(/,\s*/)
        ver.empty? ? nil : ver
      end.first
    end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
bebox-0.0.1 lib/templates/puppet/step-0/modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.6.1 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.6.0 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.5.2 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.5.1 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.5.0 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.4.1 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.4.0 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.3.3 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.3.2 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.3.1 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb
freighthop-0.3.0 modules/rbenv/lib/puppet/provider/rbenvgem/default.rb