Module: Familia::Features::ObjectIdentifier::ModelInstanceMethods
- Defined in:
- lib/familia/features/object_identifier.rb
Overview
Instance methods for object identifier management
Instance Method Summary collapse
-
#save(update_expiration: true) ⇒ Boolean
Override save to update objid_lookup mapping.
-
#save_if_not_exists(update_expiration: true) ⇒ Boolean
Override save_if_not_exists to update objid_lookup mapping.
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()
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/familia/features/object_identifier.rb', line 345 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.
367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/familia/features/object_identifier.rb', line 367 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 |