Class: Inspec::Resources::PlatformResource
- Inherits:
-
Object
- Object
- Inspec::Resources::PlatformResource
- Defined in:
- lib/resources/platform.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NameCleaned
Instance Method Summary collapse
- #[](key) ⇒ Object
- #families ⇒ Object
- #in_family?(family) ⇒ Boolean
-
#initialize ⇒ PlatformResource
constructor
A new instance of PlatformResource.
- #name ⇒ Object
- #platform?(name) ⇒ Boolean
- #supported?(supports) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ PlatformResource
Returns a new instance of PlatformResource.
17 18 19 |
# File 'lib/resources/platform.rb', line 17 def initialize @platform = inspec.backend.os end |
Instance Method Details
#[](key) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/resources/platform.rb', line 46 def [](key) # convert string to symbol key = key.to_sym if key.is_a? String return name if key == :name @platform[key] end |
#families ⇒ Object
63 64 65 |
# File 'lib/resources/platform.rb', line 63 def families @platform.family_hierarchy end |
#in_family?(family) ⇒ Boolean
59 60 61 |
# File 'lib/resources/platform.rb', line 59 def in_family?(family) @platform.family_hierarchy.include?(family) end |
#name ⇒ Object
42 43 44 |
# File 'lib/resources/platform.rb', line 42 def name NameCleaned.new(@platform.name) end |
#platform?(name) ⇒ Boolean
54 55 56 57 |
# File 'lib/resources/platform.rb', line 54 def platform?(name) @platform.name == name || @platform.family_hierarchy.include?(name) end |
#supported?(supports) ⇒ Boolean
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/resources/platform.rb', line 67 def supported?(supports) return true if supports.nil? || supports.empty? status = true supports.each do |s| s.each do |k, v| # ignore the inspec check for supports # TODO: remove in inspec 2.0 if k == :inspec next elsif %i(os_family os-family platform_family platform-family).include?(k) status = in_family?(v) elsif %i(os platform).include?(k) status = platform?(v) elsif %i(os_name os-name platform_name platform-name).include?(k) status = name == v elsif k == :release status = check_release(v) else status = false end break if status == false end return true if status == true end status end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/resources/platform.rb', line 96 def to_s 'Platform Detection' end |