Class: ActiveRecord::Locking::LockingType

Inherits:
Type::Value
  • Object
show all
Defined in:
activerecord/lib/active_record/locking/optimistic.rb

Overview

In de/serialize we change ‘nil` to 0, so that we can allow passing `nil` values to `lock_version`, and not result in `ActiveRecord::StaleObjectError` during update record.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(subtype) ⇒ Object



207
208
209
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 207

def self.new(subtype)
  self === subtype ? subtype : super
end

Instance Method Details

#deserialize(value) ⇒ Object



211
212
213
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 211

def deserialize(value)
  super.to_i
end

#encode_with(coder) ⇒ Object



223
224
225
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 223

def encode_with(coder)
  coder["subtype"] = __getobj__
end

#init_with(coder) ⇒ Object



219
220
221
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 219

def init_with(coder)
  __setobj__(coder["subtype"])
end

#serialize(value) ⇒ Object



215
216
217
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 215

def serialize(value)
  super.to_i
end