Class: Chef::Compliance::ProfileCollection
- Inherits:
-
Array
- Object
- Array
- Chef::Compliance::ProfileCollection
- Defined in:
- lib/chef/compliance/profile_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(path, cookbook_name) ⇒ Object
Add a profile to the profile collection.
-
#include_profile(arg) ⇒ Object
DSL method to enable profile files.
-
#initialize(events) ⇒ ProfileCollection
constructor
A new instance of ProfileCollection.
-
#inspec_data ⇒ Array<Profile>
Inspec profiles which are enabled in a form suitable to pass to inspec.
-
#inspect ⇒ Object
Omit the event object from error output.
-
#using_profiles? ⇒ Boolean
If any of the profiles are enabled.
Constructor Details
#initialize(events) ⇒ ProfileCollection
Returns a new instance of ProfileCollection.
30 31 32 |
# File 'lib/chef/compliance/profile_collection.rb', line 30 def initialize(events) @events = events end |
Instance Attribute Details
#events ⇒ Chef::EventDispatch::Dispatcher (readonly)
Event dispatcher for this run.
28 29 30 |
# File 'lib/chef/compliance/profile_collection.rb', line 28 def events @events end |
Instance Method Details
#from_file(path, cookbook_name) ⇒ Object
Add a profile to the profile collection. The cookbook_name needs to be determined by the caller and is used in the ‘include_profile` API to match on. The path should be the complete path on the host of the inspec.yml file, including the filename.
41 42 43 44 45 |
# File 'lib/chef/compliance/profile_collection.rb', line 41 def from_file(path, cookbook_name) new_profile = Profile.from_file(events, path, cookbook_name) self << new_profile events&.compliance_profile_loaded(new_profile) end |
#include_profile(arg) ⇒ Object
DSL method to enable profile files. This matches on the name of the profile being included it does not match on the filename of the input file. If the specific profile is omitted then it uses the default profile. The string supports regular expression matching.
include_profile “acme_cookbook::ssh-001”
include_profile “acme_cookbook”
include_profile “acme_cookbook::.*”
include_profile “acme_cookbook::ssh.*”
include_profile “.::ssh.”
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/chef/compliance/profile_collection.rb', line 82 def include_profile(arg) (cookbook_name, profile_name) = arg.split("::") profile_name = "default" if profile_name.nil? profiles = select { |profile| /^#{cookbook_name}$/.match?(profile.cookbook_name) && /^#{profile_name}$/.match?(profile.pathname) } if profiles.empty? raise "No inspec profiles matching '#{profile_name}' found in cookbooks matching '#{cookbook_name}'" end profiles.each(&:enable!) end |
#inspec_data ⇒ Array<Profile>
Returns inspec profiles which are enabled in a form suitable to pass to inspec.
54 55 56 |
# File 'lib/chef/compliance/profile_collection.rb', line 54 def inspec_data select(&:enabled?).each_with_object([]) { |profile, arry| arry << profile.inspec_data } end |
#inspect ⇒ Object
Omit the event object from error output
100 101 102 103 104 105 |
# File 'lib/chef/compliance/profile_collection.rb', line 100 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 |
#using_profiles? ⇒ Boolean
Returns if any of the profiles are enabled.
48 49 50 |
# File 'lib/chef/compliance/profile_collection.rb', line 48 def using_profiles? any?(&:enabled?) end |