Class: Minbox::Publisher

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

Constant Summary collapse

REGISTERED_PUBLISHERS =
{
  stdout: LogPublisher,
  redis: RedisPublisher,
  file: FilePublisher,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*publishers) ⇒ Publisher

Returns a new instance of Publisher.



48
49
50
# File 'lib/minbox/publisher.rb', line 48

def initialize(*publishers)
  @publishers = Array(publishers)
end

Instance Attribute Details

#publishersObject (readonly)

Returns the value of attribute publishers.



46
47
48
# File 'lib/minbox/publisher.rb', line 46

def publishers
  @publishers
end

Class Method Details

.from(outputs) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/minbox/publisher.rb', line 63

def self.from(outputs)
  publisher = Publisher.new
  outputs.each do |x|
    clazz = REGISTERED_PUBLISHERS[x.to_sym]
    publisher.add(clazz.new) if clazz
  end
  publisher
end

Instance Method Details

#add(publisher) ⇒ Object



52
53
54
# File 'lib/minbox/publisher.rb', line 52

def add(publisher)
  publishers << publisher
end

#publish(mail) ⇒ Object



56
57
58
59
60
61
# File 'lib/minbox/publisher.rb', line 56

def publish(mail)
  Thread.new do
    Minbox.logger.debug("Publishing: #{mail.message_id}")
    publishers.each { |x| x.publish(mail) }
  end
end