Class: OsCtld::DB::ObjectId
- Inherits:
-
Object
- Object
- OsCtld::DB::ObjectId
- Defined in:
- lib/osctld/db/object_id.rb
Overview
Represents object id for lookup
Object id can be given with or without pool name. Pool name can also be given as a separate option, but it does not override pool name from the id itself.
Instance Attribute Summary collapse
- #id ⇒ String readonly
- #pool ⇒ String, ... readonly
Instance Method Summary collapse
-
#initialize(id, pool = nil) ⇒ ObjectId
constructor
A new instance of ObjectId.
-
#match?(obj) ⇒ Boolean
Check if objects matches id.
Constructor Details
#initialize(id, pool = nil) ⇒ ObjectId
Returns a new instance of ObjectId.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/osctld/db/object_id.rb', line 15 def initialize(id, pool = nil) if (i = id.index(':')) @pool = id[0..i - 1] @id = id[i + 1..] else @id = id end return unless pool && @pool.nil? @pool = if pool.is_a?(Pool) pool.name elsif pool.is_a?(String) || pool.is_a?(Array) pool else raise "invalid pool type '#{pool.class}', expected OsCtld::Pool or String" end end |
Instance Attribute Details
#id ⇒ String (readonly)
11 12 13 |
# File 'lib/osctld/db/object_id.rb', line 11 def id @id end |
#pool ⇒ String, ... (readonly)
8 9 10 |
# File 'lib/osctld/db/object_id.rb', line 8 def pool @pool end |
Instance Method Details
#match?(obj) ⇒ Boolean
Check if objects matches id
37 38 39 40 41 42 43 44 45 |
# File 'lib/osctld/db/object_id.rb', line 37 def match?(obj) if @pool.nil? obj.id == @id elsif @pool.is_a?(Array) obj.id == @id && @pool.include?(obj.pool.name) else obj.pool.name == @pool && obj.id == @id end end |