Module: Familia::Features::ExternalIdentifier::ModelInstanceMethods

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

Overview

Instance methods for external identifier management

Instance Method Summary collapse

Instance Method Details

#save(update_expiration: true) ⇒ Boolean

Override save to update extid_lookup mapping

This ensures the extid_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



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/familia/features/external_identifier.rb', line 221

def save(update_expiration: true)
  result = super

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

  result
end

#save_if_not_exists(update_expiration: true) ⇒ Boolean

Override save_if_not_exists to update extid_lookup mapping

This ensures the extid_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



243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/familia/features/external_identifier.rb', line 243

def save_if_not_exists(update_expiration: true)
  result = super

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

  result
end