Class: ChefRake::Task::Gem

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/chef/raketasks/gem.rb

Instance Method Summary collapse

Constructor Details

#initializeGem

Returns a new instance of Gem.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/chef/raketasks/gem.rb', line 23

def initialize
  super

  namespace :gem do
    def install_gem(name, version, source, installdir)
      cmd = 'chef gem install '
      cmd << "#{name} "
      cmd << "-v \"#{version}\" " unless version.nil?
      cmd << "-s #{source} " unless source.nil?
      cmd << "--install-dir #{installdir} " unless installdir.nil? # used mostly for vendoring
      cmd << '--no-user-install ' unless installdir.nil? # used for vendoring
      cmd << '--no-document'

      sh cmd
    end

    desc 'gem:install'
    namespace :install do
      # NAMESPACE: gem:install:static
      desc 'Installs necessary static gems for kitchen'
      task static: %i[
        gem:install:static:kitchen
      ]
      namespace :static do
        desc 'Installs kitchen-static for kitchen'
        task :kitchen, [:version, :source] do |_t, args|
          install_gem('kitchen-static', args.version, args.source)
        end
      end

      # NAMESPACE: gem:install:vcenter
      desc 'Installs necessary vcenter gems for kitchen'
      task vcenter: %i[
        gem:install:vcenter:sdk
        gem:install:vcenter:kitchen
      ]
      namespace :vcenter do
        desc 'Installs vcenter sdk for kitchen'
        task :sdk, [:version, :source] do |_t, args|
          install_gem('vsphere-automation-sdk', args.version, args.source)
        end

        desc 'Installs kitchen-vcenter for kitchen'
        task :kitchen, [:version, :source] do |_t, args|
          install_gem('kitchen-vcenter', args.version, args.source)
        end
      end # namespace vcenter
    end # namespace install

    # NAMESPACE: gem:vendor
    desc 'Vendors gems into cookbook'
    task :vendor, [:gemname, :version, :source, :installdir] do |_t, args|
      args.with_defaults(
        version: '>= 0', # so use latest when not set
        source: nil,
        installdir: 'files/default/vendor'
      )

      install_gem(args.gemname, args.version, args.source, args.installdir)
    end
  end # namespace gem
end