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.



15
16
17
# File 'lib/inspec/resources/platform.rb', line 15

def initialize
  @platform = inspec.backend.platform
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/inspec/resources/platform.rb', line 34

def [](key)
  # convert string to symbol
  key = key.to_sym if key.is_a? String
  return name if key == :name

  @platform[key]
end

#familiesObject



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

def families
  @platform.family_hierarchy
end

#in_family?(family) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/inspec/resources/platform.rb', line 47

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

#nameObject



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

def name
  @platform.name
end

#paramsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/inspec/resources/platform.rb', line 51

def params
  h = {
    name: name,
    families: families,
    release: release,
  }

  # Avoid adding Arch for APIs (not applicable)
  unless in_family?("api")
    h[:arch] = arch
  end

  h
end

#platform?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/inspec/resources/platform.rb', line 42

def platform?(name)
  @platform.name == name ||
    @platform.family_hierarchy.include?(name)
end

#supported?(supports) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/inspec/resources/platform.rb', line 66

def supported?(supports)
  return true if supports.nil? || supports.empty?

  status = true
  supports.each do |s|
    s.each do |k, v|
      if %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_sObject



91
92
93
# File 'lib/inspec/resources/platform.rb', line 91

def to_s
  "Platform Detection"
end