Class: Inspec::Resources::OsEnv

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

Instance Method Summary collapse

Constructor Details

#initialize(env = nil, target = nil) ⇒ OsEnv

Returns a new instance of OsEnv.



24
25
26
27
28
29
30
31
32
33
# File 'lib/inspec/resources/os_env.rb', line 24

def initialize(env = nil, target = nil)
  @osenv = env
  @target = unless target.nil?
              if target.casecmp("system") == 0
                "Machine"
              else
                "User"
              end
            end
end

Instance Method Details

#contentObject



44
45
46
47
48
# File 'lib/inspec/resources/os_env.rb', line 44

def content
  return @content if defined?(@content)

  @content = value_for(@osenv, @target) unless @osenv.nil?
end

#resource_idObject



50
51
52
# File 'lib/inspec/resources/os_env.rb', line 50

def resource_id
  @osenv || ""
end

#splitObject



35
36
37
38
39
40
41
42
# File 'lib/inspec/resources/os_env.rb', line 35

def split
  # we can't take advantage of `File::PATH_SEPARATOR` as code is
  # evaluated on the host machine
  path_separator = inspec.os.windows? ? ";" : ":"
  # -1 is required to catch cases like dir1::dir2:
  # where we have a trailing :
  content.nil? ? [] : content.split(path_separator, -1)
end

#to_sObject



54
55
56
57
58
59
60
# File 'lib/inspec/resources/os_env.rb', line 54

def to_s
  if @osenv.nil?
    "Environment variables"
  else
    "Environment variable #{@osenv}"
  end
end