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


181
182
183
# File 'lib/active_record/locking/optimistic.rb', line 181

def deserialize(value)
  super.to_i
end

#encode_with(coder) ⇒ Object


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

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

#init_with(coder) ⇒ Object


189
190
191
# File 'lib/active_record/locking/optimistic.rb', line 189

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

#serialize(value) ⇒ Object


185
186
187
# File 'lib/active_record/locking/optimistic.rb', line 185

def serialize(value)
  super.to_i
end