Class: Shatter::Pidlist

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/shatter/pidlist.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePidlist

Public: Initialize the internal state of the Pidlist.


9
10
11
12
# File 'lib/shatter/pidlist.rb', line 9

def initialize
  @known = []
  @mutex = Mutex.new
end

Class Method Details

.build_fetch_by(kind) ⇒ Object

Internal: Create a method which allows for fetching a Pid by a given attribute.

Signature

by_<kind>

kind - String containing the name of the value by which to select.


42
43
44
45
46
# File 'lib/shatter/pidlist.rb', line 42

def self.build_fetch_by(kind)
  define_method("by_#{kind}") do |val|
    select { |pid| pid.send(kind) == val }
  end
end

Instance Method Details

#each(&block) ⇒ Object

Public: Iterate through known Pids.

Yields each item in the list of known Pids.

Returns nothing.


19
20
21
# File 'lib/shatter/pidlist.rb', line 19

def each(&block)
  @known.each(&block)
end

#insert(pid) ⇒ Object

Public: Add a Pid to the list of known Pids.

pid - Pid to be tracked.

Returns nothing.


28
29
30
31
32
# File 'lib/shatter/pidlist.rb', line 28

def insert(pid)
  mutex.synchronize do
    known << pid
  end
end