Class: IORequest::Utility::ExtendedID
- Inherits:
-
Object
- Object
- IORequest::Utility::ExtendedID
- Includes:
- Comparable
- Defined in:
- lib/io_request/utility/with_id.rb
Overview
Extended Id of object
Instance Attribute Summary collapse
-
#oid ⇒ Integer
readonly
Object ID.
-
#pid ⇒ Integer
readonly
Process ID.
-
#tid ⇒ Integer
readonly
Thread ID.
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison operator.
-
#initialize(pid = nil, tid = nil, oid = nil) ⇒ ExtendedID
constructor
Create new Id based on PID, thread ID and object ID.
- #to_s ⇒ String
Constructor Details
#initialize(pid = nil, tid = nil, oid = nil) ⇒ ExtendedID
Create new Id based on PID, thread ID and object ID.
11 12 13 14 15 |
# File 'lib/io_request/utility/with_id.rb', line 11 def initialize(pid = nil, tid = nil, oid = nil) @pid = pid || Process.pid @tid = tid || Thread.current.object_id @oid = oid || object_id end |
Instance Attribute Details
#oid ⇒ Integer (readonly)
Returns object ID.
24 25 26 |
# File 'lib/io_request/utility/with_id.rb', line 24 def oid @oid end |
#pid ⇒ Integer (readonly)
Returns process ID.
18 19 20 |
# File 'lib/io_request/utility/with_id.rb', line 18 def pid @pid end |
#tid ⇒ Integer (readonly)
Returns thread ID.
21 22 23 |
# File 'lib/io_request/utility/with_id.rb', line 21 def tid @tid end |
Class Method Details
.from(obj) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/io_request/utility/with_id.rb', line 42 def self.from(obj) case obj when ExtendedID then new(obj.pid, obj.tid, obj.oid) when String then new(*obj.split('#').map(&:to_i)) else raise 'unknown type' end end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison operator.
32 33 34 35 36 37 38 39 40 |
# File 'lib/io_request/utility/with_id.rb', line 32 def <=>(other) if @pid == other.pid && @tid == other.tid @oid <=> other.oid elsif @pid == other.pid && @tid != other.tid @tid <=> tid else @pid <=> other.pid end end |
#to_s ⇒ String
27 28 29 |
# File 'lib/io_request/utility/with_id.rb', line 27 def to_s "#{@pid}##{@tid}##{@oid}" end |