Class: OsEnv

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

Overview

Usage:

describe os_env(‘PATH’) do

its(:split) { should_not include('') }
its(:split) { should_not include('.') }

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ OsEnv



18
19
20
21
22
23
# File 'lib/resources/os_env.rb', line 18

def initialize(env)
  @osenv = env
  cmd = inspec.command("su - root -c 'echo $#{env}'")
  @content = cmd.stdout.chomp
  @content = nil if cmd.exit_status != 0
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



17
18
19
# File 'lib/resources/os_env.rb', line 17

def content
  @content
end

Instance Method Details

#splitObject



25
26
27
28
29
# File 'lib/resources/os_env.rb', line 25

def split
  # -1 is required to catch cases like dir1::dir2:
  # where we have a trailing :
  @content.nil? ? [] : @content.split(':', -1)
end

#to_sObject



31
32
33
# File 'lib/resources/os_env.rb', line 31

def to_s
  "Environment Variable #{@osenv}"
end