module MessageStore::StreamName

Constants

Error

Public Class Methods

category?(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 82
def self.category?(stream_name)
  !stream_name.include?(id_separator)
end
category_type_separator() click to toggle source
# File lib/message_store/stream_name.rb, line 13
def self.category_type_separator
  ':'
end
compound_id_separator() click to toggle source
# File lib/message_store/stream_name.rb, line 9
def self.compound_id_separator
  ID.compound_id_separator
end
compound_type_separator() click to toggle source
# File lib/message_store/stream_name.rb, line 17
def self.compound_type_separator
  '+'
end
get_cardinal_id(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 70
def self.get_cardinal_id(stream_name)
  id = get_id(stream_name)

  return nil if id.nil?

  ID.get_cardinal_id(id)
end
get_category(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 78
def self.get_category(stream_name)
  split(stream_name)[0]
end
get_category_type(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 86
def self.get_category_type(stream_name)
  return nil unless stream_name.include?(category_type_separator)

  category = get_category(stream_name)

  category.split(category_type_separator)[1]
end
get_category_types(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 98
def self.get_category_types(stream_name)
  type_list = get_type(stream_name)

  return [] if type_list.nil?

  type_list.split(compound_type_separator)
end
get_entity_name(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 110
def self.get_entity_name(stream_name)
  get_category(stream_name).split(category_type_separator)[0]
end
get_id(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 58
def self.get_id(stream_name)
  split(stream_name)[1]
end
get_ids(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 62
def self.get_ids(stream_name)
  ids = get_id(stream_name)

  return [] if ids.nil?

  ID.parse(ids)
end
get_type(*args) click to toggle source
# File lib/message_store/stream_name.rb, line 94
def self.get_type(*args)
  get_category_type(*args)
end
get_types(*args) click to toggle source
# File lib/message_store/stream_name.rb, line 106
def self.get_types(*args)
  get_category_types(*args)
end
id_separator() click to toggle source
# File lib/message_store/stream_name.rb, line 5
def self.id_separator
  '-'
end
split(stream_name) click to toggle source
# File lib/message_store/stream_name.rb, line 54
def self.split(stream_name)
  stream_name.split(id_separator, 2)
end
stream_name(category, stream_id=nil, cardinal_id: nil, id: nil, ids: nil, type: nil, types: nil) click to toggle source
# File lib/message_store/stream_name.rb, line 21
def self.stream_name(category, stream_id=nil, cardinal_id: nil, id: nil, ids: nil, type: nil, types: nil)
  if category == nil
    raise Error, "Category must not be omitted from stream name"
  end

  stream_name = category

  type_list = []
  type_list.concat(Array(type))
  type_list.concat(Array(types))

  type_part = type_list.join(compound_type_separator)

  if not type_part.empty?
    stream_name = "#{stream_name}#{category_type_separator}#{type_part}"
  end

  id_list = []
  id_list << cardinal_id if not cardinal_id.nil?

  id_list.concat(Array(stream_id))
  id_list.concat(Array(id))
  id_list.concat(Array(ids))

  id_part = nil
  if not id_list.empty?
    id_part = ID.compound_id(id_list)
    stream_name = "#{stream_name}#{id_separator}#{id_part}"
  end

  stream_name
end