Class: ActiveRecord::Locking::LockingType

Inherits:
Type::Value
  • Object
show all
Defined in:
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.

Instance Method Summary collapse

Instance Method Details

#deserialize(value) ⇒ Object


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

def deserialize(value)
  super.to_i
end

#encode_with(coder) ⇒ Object


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

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

#init_with(coder) ⇒ Object


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

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

#serialize(value) ⇒ Object


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

def serialize(value)
  super.to_i
end