Class: OsCtld::DB::ObjectId

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(id, pool = nil) ⇒ ObjectId

Returns a new instance of ObjectId.

Parameters:

  • id (String)
  • pool (String, Array<String>, Pool, nil) (defaults to: nil)


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

#idString (readonly)

Returns:

  • (String)


11
12
13
# File 'lib/osctld/db/object_id.rb', line 11

def id
  @id
end

#poolString, ... (readonly)

Returns:

  • (String, Array<String>, nil)


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

Parameters:

Returns:

  • (Boolean)


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