Class: Gitlab::Fp::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/fp/message.rb

Overview

A message’s content can be a hash containing any object that is relevant to the message. It will be used to provide content when the final Result from the chain is pattern matched on the message type and returned to the user. The content is required to be a hash so that it can be destructured and type-checked with rightward assignment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = {}) ⇒ Message

raise [ArgumentError] if content is not a Hash

Parameters:

  • content (Hash) (defaults to: {})

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/gitlab/fp/message.rb', line 16

def initialize(content = {})
  raise ArgumentError, 'content must be a Hash' unless content.is_a?(Hash)

  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



11
12
13
# File 'lib/gitlab/fp/message.rb', line 11

def content
  @content
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Parameters:

Returns:

  • (TrueClass, FalseClass)


24
25
26
# File 'lib/gitlab/fp/message.rb', line 24

def ==(other)
  self.class == other.class && content == other.content
end

#to_sString

Returns:

  • (String)


29
30
31
# File 'lib/gitlab/fp/message.rb', line 29

def to_s
  inspect
end