Class: ChefApply::Action::GenerateLocalPolicy

Inherits:
Base
  • Object
show all
Defined in:
lib/chef_apply/action/generate_local_policy.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #target_host

Instance Method Summary collapse

Methods inherited from Base

#name, #notify, #run

Constructor Details

#initialize(config) ⇒ GenerateLocalPolicy

Returns a new instance of GenerateLocalPolicy.



23
24
25
26
# File 'lib/chef_apply/action/generate_local_policy.rb', line 23

def initialize(config)
  super(config)
  @cookbook = config.delete :cookbook
end

Instance Attribute Details

#archive_file_locationObject (readonly)

Returns the value of attribute archive_file_location.



22
23
24
# File 'lib/chef_apply/action/generate_local_policy.rb', line 22

def archive_file_location
  @archive_file_location
end

Instance Method Details

#exporterObject



39
40
41
42
43
44
45
46
# File 'lib/chef_apply/action/generate_local_policy.rb', line 39

def exporter
  require "chef-cli/policyfile_services/export_repo"
  @exporter ||=
    ChefCLI::PolicyfileServices::ExportRepo.new(policyfile: @cookbook.policyfile_lock_path,
                                               root_dir: @cookbook.path,
                                               export_dir: @cookbook.export_path,
                                               archive: true, force: true)
end

#installerObject



48
49
50
51
52
53
# File 'lib/chef_apply/action/generate_local_policy.rb', line 48

def installer
  require "chef-cli/policyfile_services/install"
  require "chef-cli/ui"
  @installer ||=
    ChefCLI::PolicyfileServices::Install.new(ui: ChefCLI::UI.null, root_dir: @cookbook.path)
end

#perform_actionObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/chef_apply/action/generate_local_policy.rb', line 28

def perform_action
  notify(:generating)
  installer.run
  notify(:exporting)
  exporter.run
  @archive_file_location = exporter.archive_file_location
  notify(:success)
rescue ChefCLI::PolicyfileInstallError => e
  raise PolicyfileInstallError.new(e)
end