class Kriterion::Resource

Attributes

containment_path[R]
events[RW]
file[R]
line[R]
parent_uuid[RW]
provider_used[R]
resource[R]
resource_type[R]
tags[R]
title[R]
unchanged_nodes[RW]
uuid[R]

Public Class Methods

new(hash) click to toggle source
# 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
primary_key() click to toggle source
# File lib/kriterion/resource.rb, line 72
def self.primary_key
  :title
end

Public Instance Methods

==(other) click to toggle source
# File lib/kriterion/resource.rb, line 44
def ==(other)
  other.resource == resource
end
compliance() click to toggle source
# 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?() click to toggle source
# File lib/kriterion/resource.rb, line 36
def expandable?
  true
end
expandable_keys() click to toggle source
# File lib/kriterion/resource.rb, line 40
def expandable_keys
  [:events]
end