Module: Familia::Features::ObjectIdentifiers::ClassMethods

Defined in:
lib/familia/features/object_identifiers.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



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/familia/features/object_identifiers.rb', line 134

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_objidString

Generate a new object identifier using the configured strategy

Returns:

  • (String)

    A new unique identifier



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/familia/features/object_identifiers.rb', line 106

def generate_objid
  options = feature_options(:object_identifiers)
  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