Class: Inspec::Resources::Processes

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

Instance Method Summary collapse

Constructor Details

#initialize(grep = /.*/) ⇒ Processes

Returns a new instance of Processes.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/inspec/resources/processes.rb', line 30

def initialize(grep = /.*/)
  @grep = grep
  # turn into a regexp if it isn't one yet
  if grep.class == String
    # if windows ignore case as we can't make up our minds
    if inspec.os.windows?
      grep = "(?i)" + grep
    else
      grep = "(/[^/]*)*" + grep unless grep[0] == "/"
      grep = "^" + grep + '(\s|$)'
    end
    grep = Regexp.new(grep)
  end

  all_cmds = ps_axo
  @list = all_cmds.find_all do |hm|
    hm[:command] =~ grep
  end
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  !@list.empty?
end

#listObject



58
59
60
61
# File 'lib/inspec/resources/processes.rb', line 58

def list
  Inspec.deprecate(:property_processes_list, "The processes `list` property is deprecated. Please use `entries` instead.")
  @list
end

#to_sObject



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

def to_s
  "Processes #{@grep.class == String ? @grep : @grep.inspect}"
end