Class: ChefDK::Policyfile::LockApplier

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile/lock_applier.rb

Overview

A class that can apply constraints from a lock to a compiler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policyfile_lock, policyfile_compiler) ⇒ LockApplier

Initialize a LockApplier. By default, all locked data this class knows about will be applied to the compiler. Currently, it applies locks only for included policies.

Parameters:



33
34
35
36
37
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 33

def initialize(policyfile_lock, policyfile_compiler)
  @policyfile_lock = policyfile_lock
  @policyfile_compiler = policyfile_compiler
  @unlocked_policies = []
end

Instance Attribute Details

#policyfile_compilerObject (readonly)

Returns the value of attribute policyfile_compiler.



25
26
27
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 25

def policyfile_compiler
  @policyfile_compiler
end

#policyfile_lockObject (readonly)

Returns the value of attribute policyfile_lock.



24
25
26
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 24

def policyfile_lock
  @policyfile_lock
end

#unlocked_policiesObject (readonly)

Returns the value of attribute unlocked_policies.



23
24
25
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 23

def unlocked_policies
  @unlocked_policies
end

Instance Method Details

#apply!Object

Note:

No changes are applied until apply! is invoked

Apply locks described in policyfile_lock allowing for the deviations asked for.



58
59
60
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 58

def apply!
  prepare_constraints_for_policies
end

#with_unlocked_policies(policies) ⇒ Object

Unlocks included policies

Parameters:

  • policies (:all)

    Unconstrain all policies

  • policies (Array<String>)

    Unconstrain a specific policy by name



43
44
45
46
47
48
49
50
51
52
# File 'lib/chef-dk/policyfile/lock_applier.rb', line 43

def with_unlocked_policies(policies)
  if policies == :all || unlocked_policies == :all
    @unlocked_policies = :all
  else
    policies.each do |policy|
      @unlocked_policies << policy
    end
  end
  self
end