Class: Chef::Compliance::Waiver
- Inherits:
-
Object
- Object
- Chef::Compliance::Waiver
- Defined in:
- lib/chef/compliance/waiver.rb
Overview
Chef object that represents a single waiver file in the compliance segment of a cookbook
Constant Summary collapse
- HIDDEN_IVARS =
[ :@events ].freeze
Instance Attribute Summary collapse
-
#cookbook_name ⇒ String
readonly
The name of the cookbook that the waiver is in.
- #data ⇒ Object readonly private
-
#enabled ⇒ Boolean
readonly
If the waiver has been enabled.
-
#events ⇒ Chef::EventDispatch::Dispatcher
Event dispatcher for this run.
-
#path ⇒ String
readonly
The full path on the host to the waiver yml file.
-
#pathname ⇒ String
readonly
The pathname in the cookbook.
Class Method Summary collapse
- .from_file(events, filename, cookbook_name = nil) ⇒ Object
-
.from_hash(events, hash, path = nil, cookbook_name = nil) ⇒ Object
Helper to construct a waiver object from a hash.
-
.from_yaml(events, string, path = nil, cookbook_name = nil) ⇒ Object
Helper to construct a waiver object from a yaml string.
Instance Method Summary collapse
-
#disable! ⇒ Object
Set the waiver as being disabled.
-
#enable! ⇒ Object
Set the waiver to being enabled.
-
#enabled? ⇒ Boolean
If the waiver has been enabled.
-
#initialize(events, data, path, cookbook_name) ⇒ Waiver
constructor
A new instance of Waiver.
-
#inspec_data ⇒ Object
Render the waiver in a way that it can be consumed by inspec.
-
#inspect ⇒ Object
Omit the event object from error output.
Constructor Details
#initialize(events, data, path, cookbook_name) ⇒ Waiver
Returns a new instance of Waiver.
48 49 50 51 52 53 54 55 |
# 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 |
Instance Attribute Details
#cookbook_name ⇒ String (readonly)
Returns The name of the cookbook that the waiver is in.
31 32 33 |
# File 'lib/chef/compliance/waiver.rb', line 31 def cookbook_name @cookbook_name end |
#data ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/chef/compliance/waiver.rb', line 40 def data @data end |
#enabled ⇒ Boolean (readonly)
Returns if the waiver has been enabled.
28 29 30 |
# File 'lib/chef/compliance/waiver.rb', line 28 def enabled @enabled end |
#events ⇒ Chef::EventDispatch::Dispatcher
Event dispatcher for this run.
46 47 48 |
# File 'lib/chef/compliance/waiver.rb', line 46 def events @events end |
#path ⇒ String (readonly)
Returns The full path on the host to the waiver yml file.
34 35 36 |
# File 'lib/chef/compliance/waiver.rb', line 34 def path @path end |
#pathname ⇒ String (readonly)
Returns the pathname in the cookbook.
37 38 39 |
# File 'lib/chef/compliance/waiver.rb', line 37 def pathname @pathname end |
Class Method Details
.from_file(events, filename, cookbook_name = nil) ⇒ Object
110 111 112 |
# 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) ⇒ Object
Helper to construct a waiver object from a hash. Since the path and cookbook_name are required this is probably not externally useful.
96 97 98 |
# 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) ⇒ Object
Helper to construct a waiver object from a yaml string. Since the path and cookbook_name are required this is probably not externally useful.
103 104 105 |
# 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 |
Instance Method Details
#disable! ⇒ Object
Set the waiver as being disabled
72 73 74 |
# File 'lib/chef/compliance/waiver.rb', line 72 def disable! @enabled = false end |
#enable! ⇒ Object
Set the waiver to being enabled
65 66 67 68 |
# File 'lib/chef/compliance/waiver.rb', line 65 def enable! events.compliance_waiver_enabled(self) @enabled = true end |
#enabled? ⇒ Boolean
Returns if the waiver has been enabled.
59 60 61 |
# File 'lib/chef/compliance/waiver.rb', line 59 def enabled? !!@enabled end |
#inspec_data ⇒ Object
Render the waiver in a way that it can be consumed by inspec
78 79 80 |
# File 'lib/chef/compliance/waiver.rb', line 78 def inspec_data data end |
#inspect ⇒ Object
Omit the event object from error output
86 87 88 89 90 91 |
# 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 |