Module: Lockless::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/lockless/model.rb
Overview
Options:
-
:lockless_column - The columns used to track soft delete, defaults to ‘:lockless_uuid`.
Instance Method Summary collapse
-
#lockless_save ⇒ Boolean
Saves record if it has not be modified in the time after it was loaded from the database.
-
#lockless_save! ⇒ Boolean
Saves record if it has not be modified in the time after it was loaded from the database.
Instance Method Details
#lockless_save ⇒ Boolean
Saves record if it has not be modified in the time after it was loaded from the database.
false is returned if record is outdated or invalid
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/lockless/model.rb', line 32 def lockless_save return false unless valid? old_lockless_uuid = public_send(lockless_column) return save if new_record? run_callbacks(:save) do |variable| new_attrs = changed.collect { |prop| [prop.to_sym, self[prop]] }.to_h update_count = self.class.where(:id => id, lockless_column => old_lockless_uuid).update_all(new_attrs) if update_count == 1 changes_applied true else public_send("#{lockless_column}=", old_lockless_uuid) false end end end |
#lockless_save! ⇒ Boolean
Saves record if it has not be modified in the time after it was loaded from the database.
false is returned if record is outdated
57 58 59 60 |
# File 'lib/lockless/model.rb', line 57 def lockless_save! validate! lockless_save end |