Class: Minbox::Publisher

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

Constant Summary collapse

REGISTERED_PUBLISHERS =
{
  stdout: LogPublisher,
  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.



35
36
37
# File 'lib/minbox/publisher.rb', line 35

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

Instance Attribute Details

#publishersObject (readonly)

Returns the value of attribute publishers.



33
34
35
# File 'lib/minbox/publisher.rb', line 33

def publishers
  @publishers
end

Class Method Details

.from(outputs) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/minbox/publisher.rb', line 50

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



39
40
41
# File 'lib/minbox/publisher.rb', line 39

def add(publisher)
  publishers << publisher
end

#publish(mail) ⇒ Object



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

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