Class: Pubby::Stub

Inherits:
Object
  • Object
show all
Defined in:
lib/pubby/stub.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_messages = {}) ⇒ Stub



3
4
5
6
7
8
9
10
11
# File 'lib/pubby/stub.rb', line 3

def initialize(initial_messages = {})
  @messages = Hash.new { |h, k| h[k] = [] }
  
  initial_messages.each do |channel, messages|
    messages.each do |message|
      publish(channel, message)
    end
  end
end

Class Method Details

.from_config(config) ⇒ Object



30
31
32
# File 'lib/pubby/stub.rb', line 30

def self.from_config(config)
  new
end

Instance Method Details

#channelsObject



22
23
24
# File 'lib/pubby/stub.rb', line 22

def channels
  @messages.keys
end

#empty?Boolean



26
27
28
# File 'lib/pubby/stub.rb', line 26

def empty?
  @messages.empty? || @messages.all? { |k, v| v.empty? }
end

#messagesObject



18
19
20
# File 'lib/pubby/stub.rb', line 18

def messages
  @messages
end

#publish(channel_name, message) ⇒ Object



13
14
15
16
# File 'lib/pubby/stub.rb', line 13

def publish(channel_name, message)
  @messages[channel_name] << message
  true
end