Class: Inspec::Resources::PlatformResource

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

Direct Known Subclasses

OSResource

Instance Method Summary collapse

Constructor Details

#initializePlatformResource

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

#archObject



29
30
31
# File 'lib/inspec/resources/platform.rb', line 29

def arch
  @platform[:arch]
end

#familiesObject



33
34
35
# File 'lib/inspec/resources/platform.rb', line 33

def families
  @platform[:family_hierarchy]
end

#familyObject



21
22
23
# File 'lib/inspec/resources/platform.rb', line 21

def family
  @platform[:family]
end

#in_family?(family) ⇒ Boolean

Returns:

  • (Boolean)


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

def in_family?(family)
  @platform.family_hierarchy.include?(family)
end

#nameObject



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

#paramsObject



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

Returns:

  • (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

#releaseObject



25
26
27
# File 'lib/inspec/resources/platform.rb', line 25

def release
  @platform[:release]
end

#resource_idObject



96
97
98
# File 'lib/inspec/resources/platform.rb', line 96

def resource_id
  @platform.name || "platform"
end

#supported?(supports) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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_sObject



100
101
102
# File 'lib/inspec/resources/platform.rb', line 100

def to_s
  "Platform Detection"
end