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.

Instance Method Summary collapse

Instance Method Details

#deserialize(value) ⇒ Object



179
180
181
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 179

def deserialize(value)
  super.to_i
end

#encode_with(coder) ⇒ Object



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

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

#init_with(coder) ⇒ Object



187
188
189
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 187

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

#serialize(value) ⇒ Object



183
184
185
# File 'activerecord/lib/active_record/locking/optimistic.rb', line 183

def serialize(value)
  super.to_i
end