Class: Messaging::Message::Metadata

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

Defined Under Namespace

Classes: Error, Property

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.causation_attribute_namesObject



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

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

.origin_attribute_namesObject



200
201
202
203
204
205
# File 'lib/messaging/message/metadata.rb', line 200

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

.source_attribute_namesObject



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

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

.transient_attributesObject



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

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

.workflow_attribute_namesObject



207
208
209
# File 'lib/messaging/message/metadata.rb', line 207

def self.workflow_attribute_names
  causation_attribute_names + origin_attribute_names
end

Instance Method Details

#causation_message_identifierObject Also known as: causation_identifier



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

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_propertiesObject



180
181
182
# File 'lib/messaging/message/metadata.rb', line 180

def clear_properties
  properties.clear
end

#clear_reply_stream_nameObject



116
117
118
# File 'lib/messaging/message/metadata.rb', line 116

def clear_reply_stream_name
  self.reply_stream_name = nil
end

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

Returns:

  • (Boolean)


124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/messaging/message/metadata.rb', line 124

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_property(name) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/messaging/message/metadata.rb', line 168

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

  i = properties.index { |property| property.name == name }

  return nil if i.nil?

  properties.delete_at(i).value
end

#follow(preceding_metadata) ⇒ Object



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

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 |property|
    if property.local?
      next
    end

    properties << property.dup
  end
end

#follows?(preceding_metadata) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
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
# File 'lib/messaging/message/metadata.rb', line 72

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_property(name) ⇒ Object



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

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

  property = properties.find { |property| property.name == name }
  property&.value
end

#identifierObject Also known as: source_message_identifier



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

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

#reply?Boolean

Returns:

  • (Boolean)


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

def reply?
  !reply_stream_name.nil?
end

#set_local_property(name, value) ⇒ Object



155
156
157
# File 'lib/messaging/message/metadata.rb', line 155

def set_local_property(name, value)
  set_property(name, value, local: true)
end

#set_property(name, value, local: nil) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/messaging/message/metadata.rb', line 139

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

  local ||= false

  delete_property(name)

  property = Property.new(name, value, local)

  properties << property

  property
end