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()
342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/familia/features/object_identifier.rb', line 342 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.
364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/familia/features/object_identifier.rb', line 364 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 |