Class: TCB::StreamId

Inherits:
Object
  • Object
show all
Defined in:
lib/tcb/stream_id.rb

Constant Summary collapse

SEPARATOR =
"|"
NAMESPACE_SEPARATOR =
"/"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(context, id) ⇒ Object



9
10
11
# File 'lib/tcb/stream_id.rb', line 9

def build(context, id)
  new(context: context.to_s.downcase, id: id.to_s)
end

.context_from_module(mod) ⇒ Object



13
14
15
# File 'lib/tcb/stream_id.rb', line 13

def context_from_module(mod)
  DomainContext.from_module(mod).to_s
end

.parse(string) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/tcb/stream_id.rb', line 17

def parse(string)
  string = string.to_s
  parts = string.split(SEPARATOR, 2)

  if parts.size != 2 || parts.any?(&:empty?)
    raise ArgumentError, "Invalid StreamId format: #{string.inspect}. Expected \"context#{SEPARATOR}id\""
  end

  new(context: parts[0], id: parts[1])
end

Instance Method Details

#to_sObject



29
30
31
# File 'lib/tcb/stream_id.rb', line 29

def to_s
  "#{context}#{SEPARATOR}#{id}"
end