Class: Inspec::Resources::Runlevels

Inherits:
Hash
  • Object
show all
Defined in:
lib/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.



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

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

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



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

def owner
  @owner
end

Class Method Details

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



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

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



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

def disabled?
  values.none?
end

#enabled?boolean

Check if all runlevels are enabled

Returns:

  • (boolean)

    true if all runlevels are enabled



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

def enabled?
  values.all?
end

#filter(f) ⇒ Object



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

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

#to_sObject



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

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