Class: Inspec::Resources::Runlevels
- Defined in:
- lib/resources/service.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
Returns the value of attribute owner.
Class Method Summary collapse
Instance Method Summary collapse
-
#disabled? ⇒ boolean
Check if all runlevels are disabled.
-
#enabled? ⇒ boolean
Check if all runlevels are enabled.
- #filter(f) ⇒ Object
-
#initialize(owner, default = false) ⇒ Runlevels
constructor
A new instance of Runlevels.
- #to_s ⇒ Object
Methods inherited from Hash
#contains, #deep_merge, #smash
Constructor Details
#initialize(owner, default = false) ⇒ Runlevels
Returns a new instance of Runlevels.
33 34 35 36 |
# File 'lib/resources/service.rb', line 33 def initialize(owner, default = false) @owner = owner super(default) end |
Instance Attribute Details
#owner ⇒ Object
Returns the value of attribute owner.
9 10 11 |
# File 'lib/resources/service.rb', line 9 def owner @owner end |
Class Method Details
.from_hash(owner, hash = {}, filter = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/resources/service.rb', line 11 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
52 53 54 |
# File 'lib/resources/service.rb', line 52 def disabled? !values.any? end |
#enabled? ⇒ boolean
Check if all runlevels are enabled
45 46 47 |
# File 'lib/resources/service.rb', line 45 def enabled? values.all? end |
#filter(f) ⇒ Object
38 39 40 |
# File 'lib/resources/service.rb', line 38 def filter(f) Runlevels.from_hash(owner, self, f) end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/resources/service.rb', line 56 def to_s "#{owner} runlevels #{keys.join(', ')}" end |