Class: Umami::Policyfile::PolicyfileLock

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-umami/policyfile/policyfile_lock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policyfile = nil) ⇒ PolicyfileLock

Returns a new instance of PolicyfileLock.



23
24
25
26
27
28
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 23

def initialize(policyfile = nil)
  @policyfile      = policyfile
  @policyfile_lock = nil
  @storage_config  = storage_config
  @ui              = ui
end

Instance Attribute Details

#policyfileObject (readonly)

Returns the value of attribute policyfile.



22
23
24
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 22

def policyfile
  @policyfile
end

Instance Method Details

#lock_dataObject



46
47
48
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 46

def lock_data
  FFI_Yajl::Parser.new.parse(policyfile_lock_content)
end

#nameObject



57
58
59
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 57

def name
  policyfile_lock.name
end

#policyfile_lockObject



50
51
52
53
54
55
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 50

def policyfile_lock
  @policyfile_lock ||= ChefDK::PolicyfileLock.new(
    storage_config,
    ui: ui
  ).build_from_lock_data(lock_data)
end

#policyfile_lock_contentObject



42
43
44
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 42

def policyfile_lock_content
  IO.read(policyfile_lock_path)
end

#policyfile_lock_pathObject



38
39
40
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 38

def policyfile_lock_path
  policyfile.gsub(/\.rb$/, '.lock.json')
end

#storage_configObject



30
31
32
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 30

def storage_config
  @storage_config ||= ChefDK::Policyfile::StorageConfig.new.use_policyfile(policyfile)
end

#uiObject



34
35
36
# File 'lib/chef-umami/policyfile/policyfile_lock.rb', line 34

def ui
  @ui ||= ChefDK::UI.new
end