Class: ChefCLI::Policyfile::ComparisonBase::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/policyfile/comparison_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policyfile_lock_relpath) ⇒ Local

Returns a new instance of Local.



34
35
36
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 34

def initialize(policyfile_lock_relpath)
  @policyfile_lock_relpath = policyfile_lock_relpath
end

Instance Attribute Details

#policyfile_lock_relpathObject (readonly)

Returns the value of attribute policyfile_lock_relpath.



32
33
34
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 32

def policyfile_lock_relpath
  @policyfile_lock_relpath
end

Instance Method Details

#lockObject



42
43
44
45
46
47
48
49
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 42

def lock
  raise LockfileNotFound, "Expected lockfile at #{policyfile_lock_relpath} does not exist" unless File.exist?(policyfile_lock_relpath)
  raise LockfileNotFound, "Expected lockfile at #{policyfile_lock_relpath} cannot be read" unless File.readable?(policyfile_lock_relpath)

  FFI_Yajl::Parser.parse(IO.read(policyfile_lock_relpath))
rescue FFI_Yajl::ParseError => e
  raise MalformedLockfile, "Invalid JSON in lockfile at #{policyfile_lock_relpath}:\n  #{e.message}"
end

#nameObject



38
39
40
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 38

def name
  "local:#{policyfile_lock_relpath}"
end