Class: Promiscuous::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/key.rb

Instance Method Summary collapse

Constructor Details

#initialize(role, nodes = []) ⇒ Key

Returns a new instance of Key.



2
3
4
5
# File 'lib/promiscuous/key.rb', line 2

def initialize(role, nodes=[])
  @role = role
  @nodes = nodes
end

Instance Method Details

#as_json(options = {}) ⇒ Object



22
23
24
# File 'lib/promiscuous/key.rb', line 22

def as_json(options={})
  to_s
end

#join(*nodes) ⇒ Object



7
8
9
# File 'lib/promiscuous/key.rb', line 7

def join(*nodes)
  self.class.new(@role, @nodes + nodes)
end

#to_sObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/promiscuous/key.rb', line 11

def to_s
  path = []
  case @role
  when :pub then path << 'publishers'
  when :sub then path << 'subscribers'
  end
  path << Promiscuous::Config.app
  path += @nodes.compact
  path.join(':')
end