Class: Inspec::Resources::PlatformResource
- Inherits:
-
Object
- Object
- Inspec::Resources::PlatformResource
- Defined in:
- lib/inspec/resources/platform.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](key) ⇒ Object
- #arch ⇒ Object
- #families ⇒ Object
- #family ⇒ Object
- #in_family?(family) ⇒ Boolean
-
#initialize ⇒ PlatformResource
constructor
A new instance of PlatformResource.
- #name ⇒ Object
-
#normalize(key) ⇒ Object
TODO: dumb…
- #params ⇒ Object
- #platform?(name) ⇒ Boolean
- #release ⇒ Object
- #supported?(supports) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ PlatformResource
Returns a new instance of PlatformResource.
17 18 19 |
# File 'lib/inspec/resources/platform.rb', line 17 def initialize @platform = inspec.backend.platform end |
Instance Method Details
#[](key) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/inspec/resources/platform.rb', line 41 def [](key) # convert string to symbol key = key.to_sym if key.is_a? String return name if key == :name @platform[key] end |
#arch ⇒ Object
29 30 31 |
# File 'lib/inspec/resources/platform.rb', line 29 def arch @platform[:arch] end |
#families ⇒ Object
33 34 35 |
# File 'lib/inspec/resources/platform.rb', line 33 def families @platform[:family_hierarchy] end |
#family ⇒ Object
21 22 23 |
# File 'lib/inspec/resources/platform.rb', line 21 def family @platform[:family] end |
#in_family?(family) ⇒ Boolean
54 55 56 |
# File 'lib/inspec/resources/platform.rb', line 54 def in_family?(family) @platform.family_hierarchy.include?(family) end |
#name ⇒ Object
37 38 39 |
# File 'lib/inspec/resources/platform.rb', line 37 def name @platform[:name] end |
#normalize(key) ⇒ Object
TODO: dumb… push this up or remove need
92 93 94 |
# File 'lib/inspec/resources/platform.rb', line 92 def normalize(key) # TODO: dumb... push this up or remove need key.to_s.tr("-", "_").to_sym end |
#params ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/inspec/resources/platform.rb', line 58 def params # rubocop:disable Layout/AlignHash h = { name: name, families: families, release: release, arch: arch, } # rubocop:enable Layout/AlignHash h.delete :arch if in_family?("api") # not applicable if api h end |
#platform?(name) ⇒ Boolean
49 50 51 52 |
# File 'lib/inspec/resources/platform.rb', line 49 def platform?(name) @platform.name == name || @platform.family_hierarchy.include?(name) end |
#release ⇒ Object
25 26 27 |
# File 'lib/inspec/resources/platform.rb', line 25 def release @platform[:release] end |
#supported?(supports) ⇒ Boolean
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/inspec/resources/platform.rb', line 73 def supported?(supports) raise ArgumentError, "`supports` is nil." unless supports supports.any? { |support| support.all? { |k, v| case normalize(k) when :os_family, :platform_family then in_family?(v) when :os, :platform then platform?(v) when :os_name, :platform_name then check_name(v) when :release then check_release(v) end } } || supports.empty? end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/inspec/resources/platform.rb', line 96 def to_s "Platform Detection" end |