Class: Inspec::Resources::Runlevels

Inherits:
Hash
  • Object
show all
Defined in:
lib/inspec/resources/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#contains, #deep_merge, #smash

Constructor Details

#initialize(owner, default = false) ⇒ Runlevels

Returns a new instance of Runlevels.



31
32
33
34
# File 'lib/inspec/resources/service.rb', line 31

def initialize(owner, default = false)
  @owner = owner
  super(default)
end

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



7
8
9
# File 'lib/inspec/resources/service.rb', line 7

def owner
  @owner
end

Class Method Details

.from_hash(owner, hash = {}, filter = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inspec/resources/service.rb', line 9

def self.from_hash(owner, hash = {}, filter = nil)
  res = Runlevels.new(owner)
  filter = filter.first if filter.is_a?(Array) && filter.length <= 1

  ks = case filter
       when nil
         hash.keys
       when Regexp
         hash.keys.find_all { |x| x.to_s =~ filter }
       when Array
         f = filter.map(&:to_s)
         hash.keys.find_all { |x| f.include?(x.to_s) }
       when Numeric
         hash.keys.include?(filter) ? [filter] : []
       else
         hash.keys.find_all { |x| x == filter }
       end

  ks.each { |k| res[k] = hash[k] }
  res
end

Instance Method Details

#disabled?boolean

Check if all runlevels are disabled

Returns:

  • (boolean)

    true if all runlevels are disabled



50
51
52
# File 'lib/inspec/resources/service.rb', line 50

def disabled?
  values.none?
end

#enabled?boolean

Check if all runlevels are enabled

Returns:

  • (boolean)

    true if all runlevels are enabled



43
44
45
# File 'lib/inspec/resources/service.rb', line 43

def enabled?
  values.all?
end

#filter(f) ⇒ Object



36
37
38
# File 'lib/inspec/resources/service.rb', line 36

def filter(f)
  Runlevels.from_hash(owner, self, f)
end

#to_sObject



54
55
56
# File 'lib/inspec/resources/service.rb', line 54

def to_s
  "#{owner} runlevels #{keys.join(", ")}"
end