module Messaging class ExpectedVersion Error = Class.new(StandardError) attr_reader :version def initialize(version) @version = version end def any? version == :any end def none? version == :none || version == -1 end def matches?(other_version) return true if any? return true if none? && other_version == -1 return true if version == other_version false end def match!(other_version) return true if matches?(other_version) raise Error, "expected: #{version} actual: #{other_version}" end end end