Class: Messaging::ExpectedVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/messaging/expected_version.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ ExpectedVersion

Returns a new instance of ExpectedVersion.



7
8
9
# File 'lib/messaging/expected_version.rb', line 7

def initialize(version)
  @version = version
end

Instance Attribute Details

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/messaging/expected_version.rb', line 5

def version
  @version
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/messaging/expected_version.rb', line 11

def any?
  version == :any
end

#match!(other_version) ⇒ Object

Raises:



26
27
28
29
# File 'lib/messaging/expected_version.rb', line 26

def match!(other_version)
  return true if matches?(other_version)
  raise Error, "expected: #{version} actual: #{other_version}"
end

#matches?(other_version) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/messaging/expected_version.rb', line 19

def matches?(other_version)
  return true if any?
  return true if none? && other_version == -1
  return true if version == other_version
  false
end

#none?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/messaging/expected_version.rb', line 15

def none?
  version == :none || version == -1
end