Class: Messaging::Message::Metadata

Inherits:
Object
  • Object
show all
Includes:
Schema::DataStructure
Defined in:
lib/messaging/message/metadata.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.causation_attribute_namesObject



211
212
213
214
215
216
217
# File 'lib/messaging/message/metadata.rb', line 211

def self.causation_attribute_names
  [
    :causation_message_stream_name,
    :causation_message_position,
    :causation_message_global_position
  ]
end

.origin_attribute_namesObject



219
220
221
222
223
224
# File 'lib/messaging/message/metadata.rb', line 219

def self.origin_attribute_names
  [
    :correlation_stream_name,
    :reply_stream_name
  ]
end

.source_attribute_namesObject



203
204
205
206
207
208
209
# File 'lib/messaging/message/metadata.rb', line 203

def self.source_attribute_names
  [
    :stream_name,
    :position,
    :global_position
  ]
end

.transient_attributesObject



230
231
232
233
234
235
236
237
# File 'lib/messaging/message/metadata.rb', line 230

def self.transient_attributes
  [
    :stream_name,
    :position,
    :global_position,
    :time
  ]
end

.workflow_attribute_namesObject



226
227
228
# File 'lib/messaging/message/metadata.rb', line 226

def self.workflow_attribute_names
  causation_attribute_names + origin_attribute_names
end

Instance Method Details

#causation_message_identifierObject Also known as: causation_identifier



49
50
51
52
# File 'lib/messaging/message/metadata.rb', line 49

def causation_message_identifier
  return nil if causation_message_stream_name.nil? || causation_message_position.nil?
  "#{causation_message_stream_name}/#{causation_message_position}"
end

#clear_local_propertiesObject



199
200
201
# File 'lib/messaging/message/metadata.rb', line 199

def clear_local_properties
  local_properties.clear
end

#clear_propertiesObject



169
170
171
# File 'lib/messaging/message/metadata.rb', line 169

def clear_properties
  properties.clear
end

#clear_reply_stream_nameObject



120
121
122
# File 'lib/messaging/message/metadata.rb', line 120

def clear_reply_stream_name
  self.reply_stream_name = nil
end

#correlated?(stream_name) ⇒ Boolean Also known as: correlates?

Returns:

  • (Boolean)


128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/messaging/message/metadata.rb', line 128

def correlated?(stream_name)
  correlation_stream_name = self.correlation_stream_name

  return false if correlation_stream_name.nil?

  stream_name = Category.normalize(stream_name)

  if MessageStore::StreamName.category?(stream_name)
    correlation_stream_name = MessageStore::StreamName.get_category(correlation_stream_name)
  end

  correlation_stream_name == stream_name
end

#delete_local_property(name) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/messaging/message/metadata.rb', line 191

def delete_local_property(name)
  if not name.is_a?(Symbol)
    raise Error, "Local property name must be a symbol: #{name.inspect}"
  end

  local_properties.delete(name)
end

#delete_property(name) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/messaging/message/metadata.rb', line 161

def delete_property(name)
  if not name.is_a?(Symbol)
    raise Error, "Property name must be a symbol: #{name.inspect}"
  end

  properties.delete(name)
end

#follow(preceding_metadata) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/messaging/message/metadata.rb', line 55

def follow()
  self.causation_message_stream_name = .stream_name
  self.causation_message_position = .position
  self.causation_message_global_position = .global_position

  self.correlation_stream_name = .correlation_stream_name

  self.reply_stream_name = .reply_stream_name

  .properties.each do |name, value|
    properties[name] = value
  end
end

#follows?(preceding_metadata) ⇒ Boolean

Consider whether “following” takes correlation stream and reply stream into consideration. Arguably, these attributes aren’t indicative of causation. Also, follows? doesn’t take metadata into consideration What’s probably needed is a ‘copied?` predicate on metadata (without a delegation from message) Scott, Aaron, Tue Apr 11 2023

Returns:

  • (Boolean)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/messaging/message/metadata.rb', line 76

def follows?()
  if causation_message_stream_name.nil? && .stream_name.nil?
    return false
  end

  if causation_message_stream_name != .stream_name
    return false
  end


  if causation_message_position.nil? && .position.nil?
    return false
  end

  if causation_message_position != .position
    return false
  end


  if causation_message_global_position.nil? && .global_position.nil?
    return false
  end

  if causation_message_global_position != .global_position
    return false
  end


  if not .correlation_stream_name.nil?
    if correlation_stream_name != .correlation_stream_name
      return false
    end
  end


  if not .reply_stream_name.nil?
    if reply_stream_name != .reply_stream_name
      return false
    end
  end

  true
end

#get_local_property(name) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/messaging/message/metadata.rb', line 183

def get_local_property(name)
  if not name.is_a?(Symbol)
    raise Error, "Local property name must be a symbol: #{name.inspect}"
  end

  local_properties[name]
end

#get_property(name) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/messaging/message/metadata.rb', line 153

def get_property(name)
  if not name.is_a?(Symbol)
    raise Error, "Property name must be a symbol: #{name.inspect}"
  end

  properties[name]
end

#identifierObject Also known as: source_message_identifier



43
44
45
46
# File 'lib/messaging/message/metadata.rb', line 43

def identifier
  return nil if stream_name.nil? || position.nil?
  "#{stream_name}/#{position}"
end

#reply?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/messaging/message/metadata.rb', line 124

def reply?
  !reply_stream_name.nil?
end

#set_local_property(name, value) ⇒ Object



173
174
175
176
177
178
179
180
181
# File 'lib/messaging/message/metadata.rb', line 173

def set_local_property(name, value)
  if not name.is_a?(Symbol)
    raise Error, "Local property name must be a symbol: #{name.inspect}"
  end

  local_properties[name] = value

  value
end

#set_property(name, value) ⇒ Object



143
144
145
146
147
148
149
150
151
# File 'lib/messaging/message/metadata.rb', line 143

def set_property(name, value)
  if not name.is_a?(Symbol)
    raise Error, "Property name must be a symbol: #{name.inspect}"
  end

  properties[name] = value

  value
end