Class: Blabber::Blabber

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

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Blabber

Returns a new instance of Blabber.



8
9
10
11
12
13
14
15
# File 'lib/blabber.rb', line 8

def initialize(opts)
  @channels = opts.keys.map do |channel_name|\
    class_object = channel_name.split("::").inject(Object) do |acc, component|
      acc.const_get(component)
    end
    class_object.new(opts[channel_name])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



17
18
19
# File 'lib/blabber.rb', line 17

def method_missing(method_name, *args)
  process_message(args[0], method_name.to_s.upcase, args[1])
end

Instance Method Details

#process_message(message, loglevel, opts) ⇒ Object



21
22
23
24
25
# File 'lib/blabber.rb', line 21

def process_message(message, loglevel, opts)
  @channels.each do |channel|
    channel.emit(message, loglevel, opts)
  end
end