Module: Lockless::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/lockless/model.rb
Overview
Handles lockless saves
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lockless/model.rb', line 19 def lockless_save return false unless valid? old_lockless_uuid = lockless_uuid 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_uuid: old_lockless_uuid).update_all(new_attrs) if update_count == 1 changes_applied true else self.lockless_uuid = 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
44 45 46 47 |
# File 'lib/lockless/model.rb', line 44 def lockless_save! validate! lockless_save end |