Class: Chef::Compliance::Profile
- Inherits:
-
Object
- Object
- Chef::Compliance::Profile
- Defined in:
- lib/chef/compliance/profile.rb
Constant Summary collapse
- HIDDEN_IVARS =
[ :@events ].freeze
Instance Attribute Summary collapse
-
#cookbook_name ⇒ String
readonly
The name of the cookbook that the profile is in.
- #data ⇒ Object readonly private
-
#enabled ⇒ Boolean
If the profile has been enabled.
-
#events ⇒ Chef::EventDispatch::Dispatcher
readonly
Event dispatcher for this run.
-
#path ⇒ String
readonly
The full path on the host to the profile inspec.yml.
-
#pathname ⇒ String
The pathname in the cookbook.
Class Method Summary collapse
- .from_file(events, filename, cookbook_name) ⇒ Object
-
.from_hash(events, hash, path, cookbook_name) ⇒ Object
Helper to construct a profile object from a hash.
-
.from_yaml(events, string, path, cookbook_name) ⇒ Object
Helper to construct a profile object from a yaml string.
Instance Method Summary collapse
-
#disable! ⇒ Object
Set the profile as being disabled.
-
#enable! ⇒ Object
Set the profile to being enabled.
-
#enabled? ⇒ Boolean
If the profile has been enabled.
-
#initialize(events, data, path, cookbook_name) ⇒ Profile
constructor
A new instance of Profile.
-
#inspec_data ⇒ Object
Render the profile in a way that it can be consumed by inspec.
-
#inspect ⇒ Object
Omit the event object from error output.
-
#name ⇒ String
Name of the inspec profile from parsing the inspec.yml.
-
#validate! ⇒ Object
Raises if the inspec profile is not valid.
-
#version ⇒ String
Version of the inspec profile from parsing the inspec.yml.
Constructor Details
#initialize(events, data, path, cookbook_name) ⇒ Profile
Returns a new instance of Profile.
39 40 41 42 43 44 45 46 47 |
# File 'lib/chef/compliance/profile.rb', line 39 def initialize(events, data, path, cookbook_name) @events = events @data = data @path = path @cookbook_name = cookbook_name @pathname = File.basename(File.dirname(path)) disable! validate! end |
Instance Attribute Details
#cookbook_name ⇒ String (readonly)
Returns The name of the cookbook that the profile is in.
28 29 30 |
# File 'lib/chef/compliance/profile.rb', line 28 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.
37 38 39 |
# File 'lib/chef/compliance/profile.rb', line 37 def data @data end |
#enabled ⇒ Boolean
Returns if the profile has been enabled.
22 23 24 |
# File 'lib/chef/compliance/profile.rb', line 22 def enabled @enabled end |
#events ⇒ Chef::EventDispatch::Dispatcher (readonly)
Returns Event dispatcher for this run.
34 35 36 |
# File 'lib/chef/compliance/profile.rb', line 34 def events @events end |
#path ⇒ String (readonly)
Returns The full path on the host to the profile inspec.yml.
25 26 27 |
# File 'lib/chef/compliance/profile.rb', line 25 def path @path end |
#pathname ⇒ String
Returns the pathname in the cookbook.
31 32 33 |
# File 'lib/chef/compliance/profile.rb', line 31 def pathname @pathname end |
Class Method Details
.from_file(events, filename, cookbook_name) ⇒ Object
117 118 119 |
# File 'lib/chef/compliance/profile.rb', line 117 def self.from_file(events, filename, cookbook_name) from_yaml(events, IO.read(filename), filename, cookbook_name) end |
.from_hash(events, hash, path, cookbook_name) ⇒ Object
Helper to construct a profile object from a hash. Since the path and cookbook_name are required this is probably not externally useful.
103 104 105 |
# File 'lib/chef/compliance/profile.rb', line 103 def self.from_hash(events, hash, path, cookbook_name) new(events, hash, path, cookbook_name) end |
.from_yaml(events, string, path, cookbook_name) ⇒ Object
Helper to construct a profile object from a yaml string. Since the path and cookbook_name are required this is probably not externally useful.
110 111 112 |
# File 'lib/chef/compliance/profile.rb', line 110 def self.from_yaml(events, string, path, cookbook_name) from_hash(events, YAML.safe_load(string, permitted_classes: [Date]), path, cookbook_name) end |
Instance Method Details
#disable! ⇒ Object
Set the profile as being disabled
79 80 81 |
# File 'lib/chef/compliance/profile.rb', line 79 def disable! @enabled = false end |
#enable! ⇒ Object
Set the profile to being enabled
72 73 74 75 |
# File 'lib/chef/compliance/profile.rb', line 72 def enable! events.compliance_profile_enabled(self) @enabled = true end |
#enabled? ⇒ Boolean
Returns if the profile has been enabled.
66 67 68 |
# File 'lib/chef/compliance/profile.rb', line 66 def enabled? !!@enabled end |
#inspec_data ⇒ Object
Render the profile in a way that it can be consumed by inspec
85 86 87 |
# File 'lib/chef/compliance/profile.rb', line 85 def inspec_data { name: name, path: File.dirname(path) } end |
#inspect ⇒ Object
Omit the event object from error output
93 94 95 96 97 98 |
# File 'lib/chef/compliance/profile.rb', line 93 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 |
#name ⇒ String
Returns name of the inspec profile from parsing the inspec.yml.
50 51 52 |
# File 'lib/chef/compliance/profile.rb', line 50 def name @data["name"] end |
#validate! ⇒ Object
Raises if the inspec profile is not valid.
61 62 63 |
# File 'lib/chef/compliance/profile.rb', line 61 def validate! raise "Inspec profile at #{path} has no name" unless name end |
#version ⇒ String
Returns version of the inspec profile from parsing the inspec.yml.
55 56 57 |
# File 'lib/chef/compliance/profile.rb', line 55 def version @data["version"] end |