Class: Kriterion::Resource
Instance Attribute Summary collapse
-
#containment_path ⇒ Object
readonly
Returns the value of attribute containment_path.
-
#events ⇒ Object
Returns the value of attribute events.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#parent_uuid ⇒ Object
Returns the value of attribute parent_uuid.
-
#provider_used ⇒ Object
readonly
Returns the value of attribute provider_used.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resource_type ⇒ Object
readonly
Returns the value of attribute resource_type.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#unchanged_nodes ⇒ Object
Returns the value of attribute unchanged_nodes.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #compliance ⇒ Object
- #expandable? ⇒ Boolean
- #expandable_keys ⇒ Object
-
#initialize(hash) ⇒ Resource
constructor
A new instance of Resource.
Methods inherited from Object
#find_section, #flush_compliance!, #full_keys, #primary_key, #to_h
Constructor Details
#initialize(hash) ⇒ Resource
Returns a new instance of Resource.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kriterion/resource.rb', line 20 def initialize(hash) @uuid = hash['uuid'] || SecureRandom.uuid @title = hash['title'] @file = hash['file'] @line = hash['line'] @resource = hash['resource'] @resource_type = hash['resource_type'] @provider_used = hash['provider_used'] @containment_path = hash['containment_path'] @tags = hash['tags'] @events = hash['events'] || [] @parent_uuid = hash['parent_uuid'] @unchanged_nodes = hash['unchanged_nodes'] || [] @compliance = hash['compliance'] end |
Instance Attribute Details
#containment_path ⇒ Object (readonly)
Returns the value of attribute containment_path.
13 14 15 |
# File 'lib/kriterion/resource.rb', line 13 def containment_path @containment_path end |
#events ⇒ Object
Returns the value of attribute events.
16 17 18 |
# File 'lib/kriterion/resource.rb', line 16 def events @events end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
8 9 10 |
# File 'lib/kriterion/resource.rb', line 8 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
9 10 11 |
# File 'lib/kriterion/resource.rb', line 9 def line @line end |
#parent_uuid ⇒ Object
Returns the value of attribute parent_uuid.
17 18 19 |
# File 'lib/kriterion/resource.rb', line 17 def parent_uuid @parent_uuid end |
#provider_used ⇒ Object (readonly)
Returns the value of attribute provider_used.
12 13 14 |
# File 'lib/kriterion/resource.rb', line 12 def provider_used @provider_used end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
10 11 12 |
# File 'lib/kriterion/resource.rb', line 10 def resource @resource end |
#resource_type ⇒ Object (readonly)
Returns the value of attribute resource_type.
11 12 13 |
# File 'lib/kriterion/resource.rb', line 11 def resource_type @resource_type end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/kriterion/resource.rb', line 14 def @tags end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/kriterion/resource.rb', line 7 def title @title end |
#unchanged_nodes ⇒ Object
Returns the value of attribute unchanged_nodes.
18 19 20 |
# File 'lib/kriterion/resource.rb', line 18 def unchanged_nodes @unchanged_nodes end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
6 7 8 |
# File 'lib/kriterion/resource.rb', line 6 def uuid @uuid end |
Class Method Details
.primary_key ⇒ Object
72 73 74 |
# File 'lib/kriterion/resource.rb', line 72 def self.primary_key :title end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 |
# File 'lib/kriterion/resource.rb', line 44 def ==(other) other.resource == resource end |
#compliance ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/kriterion/resource.rb', line 48 def compliance # Returns cached value if it exists return @compliance if @compliance compliant = unchanged_nodes.count non_compliant = events.group_by(&:certname).count total = compliant + non_compliant percentage = if total.zero? 0 else compliant / total end { 'compliant' => events.empty?, 'events' => { 'percentage' => percentage, 'compliant' => compliant, 'non_compliant' => non_compliant, 'total' => total } } end |
#expandable? ⇒ Boolean
36 37 38 |
# File 'lib/kriterion/resource.rb', line 36 def true end |
#expandable_keys ⇒ Object
40 41 42 |
# File 'lib/kriterion/resource.rb', line 40 def [:events] end |