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


192
193
194
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 192

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

Instance Method Details

#deserialize(value) ⇒ Object


196
197
198
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 196

def deserialize(value)
  super.to_i
end

#encode_with(coder) ⇒ Object


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

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

#init_with(coder) ⇒ Object


204
205
206
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 204

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

#serialize(value) ⇒ Object


200
201
202
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 200

def serialize(value)
  super.to_i
end