Exception: PgEventstore::WrongExpectedRevisionError

Inherits:
Error
  • Object
show all
Defined in:
lib/pg_eventstore/errors.rb,
sig/pg_eventstore/errors.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#as_json, #to_h

Constructor Details

#initialize(revision:, expected_revision:, stream:, verdict:) ⇒ WrongExpectedRevisionError

Returns a new instance of WrongExpectedRevisionError.

Parameters:

  • revision (Integer)
  • expected_revision (Integer, Symbol)
  • stream (PgEventstore::Stream)
  • verdict (Symbol)
  • revision: (Integer)
  • expected_revision: (Integer, Symbol)
  • stream: (Stream)
  • verdict: (Symbol)


66
67
68
69
70
71
72
# File 'lib/pg_eventstore/errors.rb', line 66

def initialize(revision:, expected_revision:, stream:, verdict:)
  @revision = revision
  @expected_revision = expected_revision
  @stream = stream
  @verdict = verdict
  super(user_friendly_message)
end

Instance Attribute Details

#expected_revisionInteger, Symbol

Returns the value of attribute expected_revision.

Returns:

  • (Integer, Symbol)


57
58
59
# File 'lib/pg_eventstore/errors.rb', line 57

def expected_revision
  @expected_revision
end

#revisionInteger

Returns the value of attribute revision.

Returns:

  • (Integer)


54
55
56
# File 'lib/pg_eventstore/errors.rb', line 54

def revision
  @revision
end

#streamStream

Returns the value of attribute stream.

Returns:



51
52
53
# File 'lib/pg_eventstore/errors.rb', line 51

def stream
  @stream
end

#verdictSymbol

Returns the value of attribute verdict.

Returns:

  • (Symbol)


60
61
62
# File 'lib/pg_eventstore/errors.rb', line 60

def verdict
  @verdict
end

Instance Method Details

#current_no_streamString

Returns:

  • (String)


103
104
105
# File 'lib/pg_eventstore/errors.rb', line 103

def current_no_stream
  "#{stream_descr} stream revision #{expected_revision.inspect} is expected, but stream does not exist."
end

#expected_no_streamString

Returns:

  • (String)


98
99
100
# File 'lib/pg_eventstore/errors.rb', line 98

def expected_no_stream
  "Expected stream #{stream_descr} to be absent, but it actually exists."
end

#expected_stream_existsString

Returns:

  • (String)


93
94
95
# File 'lib/pg_eventstore/errors.rb', line 93

def expected_stream_exists
  "Expected stream #{stream_descr} to exist, but it doesn't."
end

#stream_descrString

Returns:

  • (String)


116
117
118
# File 'lib/pg_eventstore/errors.rb', line 116

def stream_descr
  stream.to_hash.inspect
end

#unmatched_stream_revisionString

Returns:

  • (String)


108
109
110
111
112
113
# File 'lib/pg_eventstore/errors.rb', line 108

def unmatched_stream_revision
  <<~TEXT.strip
    #{stream_descr} stream revision #{expected_revision.inspect} is expected, but actual stream revision is \
    #{revision.inspect}.
  TEXT
end

#user_friendly_messageString

Returns:

  • (String)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pg_eventstore/errors.rb', line 77

def user_friendly_message
  case verdict
  when :expected_to_have_stream_with_given_revision
    current_no_stream
  when :unmatched_stream_revision
    unmatched_stream_revision
  when :expected_to_have_stream
    expected_stream_exists
  when :expected_not_to_have_stream
    expected_no_stream
  else
    Utils.missing_implementation!(verdict)
  end
end