Module: EventSource::StreamName

Defined in:
lib/event_source/stream_name.rb

Class Method Summary collapse

Class Method Details

.category?(stream_name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/event_source/stream_name.rb', line 26

def self.category?(stream_name)
  !stream_name.include?('-')
end

.get_category(stream_name) ⇒ Object



22
23
24
# File 'lib/event_source/stream_name.rb', line 22

def self.get_category(stream_name)
  stream_name.split('-')[0]
end

.get_id(stream_name) ⇒ Object



17
18
19
20
# File 'lib/event_source/stream_name.rb', line 17

def self.get_id(stream_name)
  id = stream_name.partition('-')[2]
  id.empty? ? nil : id
end

.get_type_list(name) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/event_source/stream_name.rb', line 30

def self.get_type_list(name)
  type = name.split(':').last.split('-').first

  return nil if name.start_with?(type)

  type
end

.get_types(name) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/event_source/stream_name.rb', line 38

def self.get_types(name)
  type_list = get_type_list(name)

  return [] if type_list.nil?

  type_list.split('+')
end

.stream_name(category_name, id = nil, type: nil, types: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/event_source/stream_name.rb', line 3

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