Class: ChefRake::Task::Repin

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

Instance Method Summary collapse

Constructor Details

#initializeRepin

Returns a new instance of Repin.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chef/raketasks/repin.rb', line 23

def initialize
  super

  namespace :repin do
    desc 'Repin hard dependencies in Chef Workstation binaries'

    %w[chef-client kitchen inspec ohai].each do |binary|
      next unless File.exist? binary_wrapper(binary)

      desc "Repin #{binary} dependency to a specific gem"
      task binary.to_sym, [:gem, :version] do |_task, args|
        task_repin binary, args.gem, args.version
      end
    end
  end # namespace repin
end

Instance Method Details

#binary_wrapper(name) ⇒ Object



46
47
48
# File 'lib/chef/raketasks/repin.rb', line 46

def binary_wrapper(name)
  File.join('/opt/chef-workstation/bin', name)
end

#read(filename) ⇒ Object



50
51
52
53
# File 'lib/chef/raketasks/repin.rb', line 50

def read(filename)
  @contents = File.read(filename)
  @filename = filename
end

#repin(gem, version) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/chef/raketasks/repin.rb', line 55

def repin(gem, version)
  printf("Changing version pin of %<gem>s to %<version>s for %<binary>s\n",
         gem: gem,
         version: version,
         binary: @filename)

  @contents.gsub!(/(?<=#{gem}"), "= [.0-9]+"/, ", \"= #{version}\"")
end

#task_repin(name, gem, version) ⇒ Object

def initialize



40
41
42
43
44
# File 'lib/chef/raketasks/repin.rb', line 40

def task_repin(name, gem, version)
  read binary_wrapper(name)
  repin gem, version
  write_back
end

#write_backObject



64
65
66
# File 'lib/chef/raketasks/repin.rb', line 64

def write_back
  File.write(@filename, @contents)
end