Module: Familia::Features::ObjectIdentifier::ModelInstanceMethods

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

Overview

Instance methods for object identifier management

Instance Method Summary collapse

Instance Method Details

#save(update_expiration: true) ⇒ Boolean

Override save to update objid_lookup mapping

This ensures the objid_lookup index is populated during save operations rather than during object initialization, preventing unwanted database writes when calling .new()

Parameters:

  • update_expiration (Boolean) (defaults to: true)

    Whether to update key expiration

Returns:

  • (Boolean)

    True if save was successful



293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/familia/features/object_identifier.rb', line 293

def save(update_expiration: true)
  result = super

  # Update objid_lookup mapping after successful save
  if result && respond_to?(:objid) && respond_to?(:identifier)
    current_objid = objid  # Triggers lazy generation if needed
    if current_objid && identifier
      self.class.objid_lookup[current_objid] = identifier
    end
  end

  result
end

#save_if_not_exists(update_expiration: true) ⇒ Boolean

Override save_if_not_exists to update objid_lookup mapping

This ensures the objid_lookup index is populated during create operations which use save_if_not_exists instead of save.

Parameters:

  • update_expiration (Boolean) (defaults to: true)

    Whether to update key expiration

Returns:

  • (Boolean)

    True if save was successful



315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/familia/features/object_identifier.rb', line 315

def save_if_not_exists(update_expiration: true)
  result = super

  # Update objid_lookup mapping after successful save
  if result && respond_to?(:objid) && respond_to?(:identifier)
    current_objid = objid  # Triggers lazy generation if needed
    if current_objid && identifier
      self.class.objid_lookup[current_objid] = identifier
    end
  end

  result
end