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()
295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/familia/features/object_identifier.rb', line 295 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.
317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/familia/features/object_identifier.rb', line 317 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 |