Class: Chef::Compliance::Input
- Inherits:
-
Object
- Object
- Chef::Compliance::Input
- Defined in:
- lib/chef/compliance/input.rb
Overview
Chef object that represents a single input 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 input is in.
- #data ⇒ Object readonly private
-
#enabled ⇒ Boolean
readonly
If the input has been enabled.
-
#events ⇒ Chef::EventDispatch::Dispatcher
readonly
Event dispatcher for this run.
-
#path ⇒ String
readonly
The full path on the host to the input 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 input object from a hash.
-
.from_yaml(events, string, path = nil, cookbook_name = nil) ⇒ Object
Helper to construct a input object from a yaml string.
Instance Method Summary collapse
-
#disable! ⇒ Object
Set the input as being disabled.
-
#enable! ⇒ Object
Set the input to being enabled.
-
#enabled? ⇒ Boolean
If the input has been enabled.
-
#initialize(events, data, path, cookbook_name) ⇒ Input
constructor
A new instance of Input.
-
#inspec_data ⇒ Object
Render the input 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) ⇒ Input
Returns a new instance of Input.
48 49 50 51 52 53 54 55 |
# 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 |
Instance Attribute Details
#cookbook_name ⇒ String (readonly)
Returns The name of the cookbook that the input is in.
31 32 33 |
# File 'lib/chef/compliance/input.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.
46 47 48 |
# File 'lib/chef/compliance/input.rb', line 46 def data @data end |
#enabled ⇒ Boolean (readonly)
Returns if the input has been enabled.
28 29 30 |
# File 'lib/chef/compliance/input.rb', line 28 def enabled @enabled end |
#events ⇒ Chef::EventDispatch::Dispatcher (readonly)
Event dispatcher for this run.
43 44 45 |
# File 'lib/chef/compliance/input.rb', line 43 def events @events end |
#path ⇒ String (readonly)
Returns The full path on the host to the input yml file.
34 35 36 |
# File 'lib/chef/compliance/input.rb', line 34 def path @path end |
#pathname ⇒ String (readonly)
Returns the pathname in the cookbook.
37 38 39 |
# File 'lib/chef/compliance/input.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/input.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 input 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/input.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 input 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/input.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 input as being disabled
72 73 74 |
# File 'lib/chef/compliance/input.rb', line 72 def disable! @enabled = false end |
#enable! ⇒ Object
Set the input to being enabled
65 66 67 68 |
# File 'lib/chef/compliance/input.rb', line 65 def enable! events.compliance_input_enabled(self) @enabled = true end |
#enabled? ⇒ Boolean
Returns if the input has been enabled.
59 60 61 |
# File 'lib/chef/compliance/input.rb', line 59 def enabled? !!@enabled end |
#inspec_data ⇒ Object
Render the input in a way that it can be consumed by inspec
78 79 80 |
# File 'lib/chef/compliance/input.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/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 |