Class: Kriterion::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/kriterion/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_pathObject (readonly)

Returns the value of attribute containment_path.



13
14
15
# File 'lib/kriterion/resource.rb', line 13

def containment_path
  @containment_path
end

#eventsObject

Returns the value of attribute events.



16
17
18
# File 'lib/kriterion/resource.rb', line 16

def events
  @events
end

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/kriterion/resource.rb', line 8

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



9
10
11
# File 'lib/kriterion/resource.rb', line 9

def line
  @line
end

#parent_uuidObject

Returns the value of attribute parent_uuid.



17
18
19
# File 'lib/kriterion/resource.rb', line 17

def parent_uuid
  @parent_uuid
end

#provider_usedObject (readonly)

Returns the value of attribute provider_used.



12
13
14
# File 'lib/kriterion/resource.rb', line 12

def provider_used
  @provider_used
end

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/kriterion/resource.rb', line 10

def resource
  @resource
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



11
12
13
# File 'lib/kriterion/resource.rb', line 11

def resource_type
  @resource_type
end

#tagsObject (readonly)

Returns the value of attribute tags.



14
15
16
# File 'lib/kriterion/resource.rb', line 14

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/kriterion/resource.rb', line 7

def title
  @title
end

#unchanged_nodesObject

Returns the value of attribute unchanged_nodes.



18
19
20
# File 'lib/kriterion/resource.rb', line 18

def unchanged_nodes
  @unchanged_nodes
end

#uuidObject (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_keyObject



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

#complianceObject



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

Returns:

  • (Boolean)


36
37
38
# File 'lib/kriterion/resource.rb', line 36

def expandable?
  true
end

#expandable_keysObject



40
41
42
# File 'lib/kriterion/resource.rb', line 40

def expandable_keys
  [:events]
end