module EventSource::Postgres::StreamName

Public Class Methods

category?(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 27
def self.category?(stream_name)
  !stream_name.include?('-')
end
get_category(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 23
def self.get_category(stream_name)
  stream_name.split('-').first
end
get_entity_name(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 47
def self.get_entity_name(stream_name)
  get_category(stream_name).split(':').first
end
get_id(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 18
def self.get_id(stream_name)
  id = stream_name.partition('-').last
  id.empty? ? nil : id
end
get_type_list(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 31
def self.get_type_list(stream_name)
  type = stream_name.split(':').last.split('-').first

  return nil if stream_name.start_with?(type)

  type
end
get_types(stream_name) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 39
def self.get_types(stream_name)
  type_list = get_type_list(stream_name)

  return [] if type_list.nil?

  type_list.split('+')
end
stream_name(category_name, id=nil, type: nil, types: nil) click to toggle source
# File lib/event_source/postgres/stream_name.rb, line 4
def self.stream_name(category_name, id=nil, type: nil, types: nil)
  types = Array(types)
  types.unshift(type) unless type.nil?

  type_list = nil
  type_list = types.join('+') unless types.empty?

  stream_name = category_name
  stream_name = "#{stream_name}:#{type_list}" unless type_list.nil?
  stream_name = "#{stream_name}-#{id}" unless id.nil?

  stream_name
end