Class: RubyEventStore::ExpectedVersion
- Inherits:
-
Object
- Object
- RubyEventStore::ExpectedVersion
- Defined in:
- lib/ruby_event_store/expected_version.rb
Constant Summary collapse
- POSITION_DEFAULT =
-1.freeze
- NOT_RESOLVED =
Object.new.freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_expected_version) ⇒ Object (also: #eql?)
- #any? ⇒ Boolean
- #auto? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(version) ⇒ ExpectedVersion
constructor
A new instance of ExpectedVersion.
- #none? ⇒ Boolean
- #resolve_for(stream, resolver = Proc.new {}) ⇒ Object
Constructor Details
#initialize(version) ⇒ ExpectedVersion
Returns a new instance of ExpectedVersion.
22 23 24 25 |
# File 'lib/ruby_event_store/expected_version.rb', line 22 def initialize(version) @version = version invalid_version! unless [Integer, :any, :none, :auto].any? { |i| i === version } end |
Instance Attribute Details
#version ⇒ Object (readonly)
Returns the value of attribute version.
20 21 22 |
# File 'lib/ruby_event_store/expected_version.rb', line 20 def version @version end |
Class Method Details
.any ⇒ Object
8 9 10 |
# File 'lib/ruby_event_store/expected_version.rb', line 8 def self.any new(:any) end |
.auto ⇒ Object
16 17 18 |
# File 'lib/ruby_event_store/expected_version.rb', line 16 def self.auto new(:auto) end |
.none ⇒ Object
12 13 14 |
# File 'lib/ruby_event_store/expected_version.rb', line 12 def self.none new(:none) end |
Instance Method Details
#==(other_expected_version) ⇒ Object Also known as: eql?
56 57 58 |
# File 'lib/ruby_event_store/expected_version.rb', line 56 def ==(other_expected_version) other_expected_version.instance_of?(self.class) && other_expected_version.version.equal?(version) end |
#any? ⇒ Boolean
27 28 29 |
# File 'lib/ruby_event_store/expected_version.rb', line 27 def any? version.equal?(:any) end |
#auto? ⇒ Boolean
31 32 33 |
# File 'lib/ruby_event_store/expected_version.rb', line 31 def auto? version.equal?(:auto) end |
#hash ⇒ Object
52 53 54 |
# File 'lib/ruby_event_store/expected_version.rb', line 52 def hash version.hash ^ self.class.hash end |
#none? ⇒ Boolean
35 36 37 |
# File 'lib/ruby_event_store/expected_version.rb', line 35 def none? version.equal?(:none) end |
#resolve_for(stream, resolver = Proc.new {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_event_store/expected_version.rb', line 39 def resolve_for(stream, resolver = Proc.new {}) invalid_version! if stream.global? && !any? case version when Integer version when :none POSITION_DEFAULT when :auto resolver[stream] || POSITION_DEFAULT end end |