class Chef::Compliance::Input
Chef
object that represents a single input file in the compliance segment of a cookbook.
Constants
- HIDDEN_IVARS
Attributes
@return [String] The name of the cookbook that the input is in
@api private
@return [Boolean] if the input has been enabled
Event dispatcher for this run.
@return [Chef::EventDispatch::Dispatcher]
@return [String] The full path on the host to the input yml file
@return [String] the pathname in the cookbook
Public Class Methods
@param filename [String] full path to the yml file in the cookbook @param cookbook_name
[String] cookbook that the input is in
# File lib/chef/compliance/input.rb, line 110 def self.from_file(events, filename, cookbook_name = nil) from_yaml(events, IO.read(filename), filename, cookbook_name) end
Helper to construct a input object from a hash. Since the path and cookbook_name
are required this is probably not externally useful.
# File lib/chef/compliance/input.rb, line 96 def self.from_hash(events, hash, path = nil, cookbook_name = nil) new(events, hash, path, cookbook_name) end
Helper to construct a input object from a yaml string. Since the path and cookbook_name
are required this is probably not externally useful.
# File lib/chef/compliance/input.rb, line 103 def self.from_yaml(events, string, path = nil, cookbook_name = nil) from_hash(events, YAML.load(string), path, cookbook_name) end
# File lib/chef/compliance/input.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
Set the input as being disabled
# File lib/chef/compliance/input.rb, line 72 def disable! @enabled = false end
Set the input to being enabled
# File lib/chef/compliance/input.rb, line 65 def enable! events.compliance_input_enabled(self) @enabled = true end
@return [Boolean] if the input has been enabled
# File lib/chef/compliance/input.rb, line 59 def enabled? !!@enabled end
Render the input in a way that it can be consumed by inspec
# File lib/chef/compliance/input.rb, line 78 def inspec_data data end
Omit the event object from error output
# File lib/chef/compliance/input.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