Class: Chef::Compliance::InputCollection
- Inherits:
-
Array
- Object
- Array
- Chef::Compliance::InputCollection
- Defined in:
- lib/chef/compliance/input_collection.rb
Constant Summary collapse
- HIDDEN_IVARS =
[ :@events ].freeze
Instance Attribute Summary collapse
-
#events ⇒ Chef::EventDispatch::Dispatcher
readonly
Event dispatcher for this run.
Instance Method Summary collapse
-
#from_file(filename, cookbook_name) ⇒ Object
Add a input to the input collection.
-
#from_hash(hash) ⇒ Object
Add a input from a raw hash.
-
#include_input(arg) ⇒ Object
DSL method to enable input files.
-
#initialize(events) ⇒ InputCollection
constructor
A new instance of InputCollection.
-
#inspec_data ⇒ Array<Input>
Inspec inputs which are enabled in a form suitable to pass to inspec.
-
#inspect ⇒ Object
Omit the event object from error output.
- #valid?(arg) ⇒ Boolean
Constructor Details
#initialize(events) ⇒ InputCollection
Returns a new instance of InputCollection.
29 30 31 |
# File 'lib/chef/compliance/input_collection.rb', line 29 def initialize(events) @events = events end |
Instance Attribute Details
#events ⇒ Chef::EventDispatch::Dispatcher (readonly)
Event dispatcher for this run.
27 28 29 |
# File 'lib/chef/compliance/input_collection.rb', line 27 def events @events end |
Instance Method Details
#from_file(filename, cookbook_name) ⇒ Object
Add a input to the input collection. The cookbook_name needs to be determined by the caller and is used in the ‘include_input` API to match on. The path should be the complete path on the host of the yml file, including the filename.
40 41 42 43 44 |
# File 'lib/chef/compliance/input_collection.rb', line 40 def from_file(filename, cookbook_name) new_input = Input.from_file(events, filename, cookbook_name) self << new_input events&.compliance_input_loaded(new_input) end |
#from_hash(hash) ⇒ Object
Add a input from a raw hash. This input will be enabled by default.
51 52 53 54 55 |
# File 'lib/chef/compliance/input_collection.rb', line 51 def from_hash(hash) new_input = Input.from_hash(events, hash) new_input.enable! self << new_input end |
#include_input(arg) ⇒ Object
DSL method to enable input files. This matches on the filename of the input file. If the specific input is omitted then it uses the default input. The string supports regular expression matching.
include_input “acme_cookbook::ssh-001”
include_input “acme_cookbook”
include_input “acme_cookbook::.*”
include_input “acme_cookbook::ssh.*”
include_input “.::ssh.”
include_input({ “ssh_custom_path”: “/usr/local/bin” })
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/chef/compliance/input_collection.rb', line 91 def include_input(arg) raise "include_input was given a nil value" if arg.nil? # if we're given a hash argument just shove it in the raw_hash if arg.is_a?(Hash) from_hash(arg) return end matching_inputs(arg).each(&:enable!) end |
#inspec_data ⇒ Array<Input>
Returns inspec inputs which are enabled in a form suitable to pass to inspec.
59 60 61 |
# File 'lib/chef/compliance/input_collection.rb', line 59 def inspec_data select(&:enabled?).each_with_object({}) { |input, hash| hash.merge!(input.inspec_data) } end |
#inspect ⇒ Object
Omit the event object from error output
111 112 113 114 115 116 |
# File 'lib/chef/compliance/input_collection.rb', line 111 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 |
#valid?(arg) ⇒ Boolean
103 104 105 |
# File 'lib/chef/compliance/input_collection.rb', line 103 def valid?(arg) !matching_inputs(arg).empty? end |