class Chef::Compliance::Waiver

Chef object that represents a single waiver file in the compliance segment of a cookbook

Constants

HIDDEN_IVARS

Attributes

cookbook_name[R]

@return [String] The name of the cookbook that the waiver is in

data[R]

@api private

enabled[R]

@return [Boolean] if the waiver has been enabled

events[RW]

Event dispatcher for this run.

@return [Chef::EventDispatch::Dispatcher]

path[R]

@return [String] The full path on the host to the waiver yml file

pathname[R]

@return [String] the pathname in the cookbook

Public Class Methods

from_file(events, filename, cookbook_name = nil) click to toggle source

@param filename [String] full path to the yml file in the cookbook @param cookbook_name [String] cookbook that the waiver is in

# File lib/chef/compliance/waiver.rb, line 110
def self.from_file(events, filename, cookbook_name = nil)
  from_yaml(events, IO.read(filename), filename, cookbook_name)
end
from_hash(events, hash, path = nil, cookbook_name = nil) click to toggle source

Helper to construct a waiver object from a hash. Since the path and cookbook_name are required this is probably not externally useful.

# File lib/chef/compliance/waiver.rb, line 96
def self.from_hash(events, hash, path = nil, cookbook_name = nil)
  new(events, hash, path, cookbook_name)
end
from_yaml(events, string, path = nil, cookbook_name = nil) click to toggle source

Helper to construct a waiver object from a yaml string. Since the path and cookbook_name are required this is probably not externally useful.

# File lib/chef/compliance/waiver.rb, line 103
def self.from_yaml(events, string, path = nil, cookbook_name = nil)
  from_hash(events, YAML.safe_load(string, permitted_classes: [Date]), path, cookbook_name)
end
new(events, data, path, cookbook_name) click to toggle source
# File lib/chef/compliance/waiver.rb, line 48
def initialize(events, data, path, cookbook_name)
  @events = events
  @data = data
  @cookbook_name = cookbook_name
  @path = path
  @pathname = File.basename(path, File.extname(path)) unless path.nil?
  disable!
end

Public Instance Methods

disable!() click to toggle source

Set the waiver as being disabled

# File lib/chef/compliance/waiver.rb, line 72
def disable!
  @enabled = false
end
enable!() click to toggle source

Set the waiver to being enabled

# File lib/chef/compliance/waiver.rb, line 65
def enable!
  events.compliance_waiver_enabled(self)
  @enabled = true
end
enabled?() click to toggle source

@return [Boolean] if the waiver has been enabled

# File lib/chef/compliance/waiver.rb, line 59
def enabled?
  !!@enabled
end
inspec_data() click to toggle source

Render the waiver in a way that it can be consumed by inspec

# File lib/chef/compliance/waiver.rb, line 78
def inspec_data
  data
end
inspect() click to toggle source

Omit the event object from error output

# File lib/chef/compliance/waiver.rb, line 86
def inspect
  ivar_string = (instance_variables.map(&:to_sym) - HIDDEN_IVARS).map do |ivar|
    "#{ivar}=#{instance_variable_get(ivar).inspect}"
  end.join(", ")
  "#<#{self.class}:#{object_id} #{ivar_string}>"
end