Class: Collective::Key
- Inherits:
-
Object
- Object
- Collective::Key
- Defined in:
- lib/collective/key.rb
Overview
A key uniquely identifies a worker.
Defined Under Namespace
Classes: MalformedKey
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, pid, host = Collective::Key.local_host) ⇒ Key
constructor
A new instance of Key.
-
#to_s ⇒ Object
e.g.
Constructor Details
#initialize(name, pid, host = Collective::Key.local_host) ⇒ Key
Returns a new instance of Key.
15 16 17 18 19 |
# File 'lib/collective/key.rb', line 15 def initialize( name, pid, host = Collective::Key.local_host ) @name = name @pid = pid.to_i @host = host end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/collective/key.rb', line 13 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/collective/key.rb', line 11 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
12 13 14 |
# File 'lib/collective/key.rb', line 12 def pid @pid end |
Class Method Details
.local_host ⇒ Object
41 42 43 |
# File 'lib/collective/key.rb', line 41 def self.local_host @local_host ||= `hostname`.chomp.strip end |
.parse(key_string) ⇒ Object
31 32 33 34 |
# File 'lib/collective/key.rb', line 31 def self.parse(key_string) key_string =~ /^(.*)-([0-9]+)@([^@]+)$/ or raise MalformedKey.new(key_string) new( $1, $2, $3 ) end |
Instance Method Details
#==(other) ⇒ Object
21 22 23 24 |
# File 'lib/collective/key.rb', line 21 def ==(other) self.equal?(other) || ( name == other.name && pid == other.pid && host == other.host ) end |
#to_s ⇒ Object
e.g. [email protected]
27 28 29 |
# File 'lib/collective/key.rb', line 27 def to_s "%s-%i@%s" % [ name, pid, host ] end |