Class: Cloudscopes::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscopes/process.rb

Defined Under Namespace

Classes: SystemProcess

Instance Method Summary collapse

Instance Method Details

#listObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/cloudscopes/process.rb', line 68

def list
  list = Dir["/proc/[0-9]*[0-9]"].collect{|dir| SystemProcess.new(File.basename(dir).to_i) }
  list.define_singleton_method(:method_missing) do |name, *args|
    case name.to_s
    when /^by_(.*)/
      field = $1.to_sym
      raise ArgumentError.new("wrong number of arguments (#{args.length} for 1)") unless args.length == 1
      select do |ps| 
        case ps.send(field)
        when args.first
          true
        else
          false
        end
      end
    else
      raise NoMethodError.new("No such method #{name}",name)
    end
  end
  list
end