Module: Familia::Features::ObjectIdentifier::ClassMethods

Defined in:
lib/familia/features/object_identifier.rb

Instance Method Summary collapse

Instance Method Details

#find_by_objid(objid) ⇒ Object?

Find an object by its object identifier

Parameters:

  • objid (String)

    The object identifier to search for

Returns:

  • (Object, nil)

    The object if found, nil otherwise



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/familia/features/object_identifier.rb', line 239

def find_by_objid(objid)
  return nil if objid.to_s.empty?

  if Familia.debug?
    reference = caller(1..1).first
    Familia.trace :FIND_BY_OBJID, Familia.dbclient, objid, reference
  end

  # Use the object identifier as the key for lookup
  # This is a simple stub implementation - would need more sophisticated
  # search logic in a real application
  find_by_id(objid)
rescue Familia::NotFound
  nil
end

#generate_object_identifierString

Generate a new object identifier using the configured strategy

Returns:

  • (String)

    A new unique identifier



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/familia/features/object_identifier.rb', line 211

def generate_object_identifier
  options = feature_options(:object_identifier)
  generator = options[:generator] || DEFAULT_GENERATOR

  case generator
  when :uuid_v7
    SecureRandom.uuid_v7
  when :uuid_v4
    SecureRandom.uuid_v4
  when :hex
    Familia.generate_hex_id
  when Proc
    generator.call
  else
    unless generator.respond_to?(:call)
      raise Familia::Problem, "Invalid object identifier generator: #{generator.inspect}"
    end

    generator.call

  end
end