Sha256: 700978d84acf2f8bfe31ef0a5ae897c977b496e4da3ec59f30dbd64fb60b9a45
Contents?: true
Size: 518 Bytes
Versions: 6
Compression:
Stored size: 518 Bytes
Contents
module Ohm module Versioned def self.included(model) model.attribute :_version, ->(x) { x.to_i } end def save current_version = new? ? 0 : redis.call("HGET", key, :_version).to_i if current_version != _version raise Ohm::VersionConflict.new(attributes) end self._version = current_version + 1 super end end class VersionConflict < StandardError attr :attributes def initialize(attributes) @attributes = attributes end end end
Version data entries
6 entries across 6 versions & 1 rubygems