Class: Inspec::Resources::Processes

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grep) ⇒ Processes

Returns a new instance of Processes.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/resources/processes.rb', line 23

def initialize(grep)
  # turn into a regexp if it isn't one yet
  if grep.class == String
    grep = '(/[^/]*)*'+grep if grep[0] != '/'
    grep = Regexp.new('^' + grep + '(\s|$)')
  end

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

  { users: :user,
    states: :stat }.each do |var, key|
    instance_variable_set("@#{var}", @list.map { |l| l[key] }.uniq)
  end
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



19
20
21
# File 'lib/resources/processes.rb', line 19

def list
  @list
end

#statesObject (readonly)

Returns the value of attribute states.



19
20
21
# File 'lib/resources/processes.rb', line 19

def states
  @states
end

#usersObject (readonly)

Returns the value of attribute users.



19
20
21
# File 'lib/resources/processes.rb', line 19

def users
  @users
end

Instance Method Details

#to_sObject



41
42
43
# File 'lib/resources/processes.rb', line 41

def to_s
  'Processes'
end