Class: Nuntius::BaseMessageBox

Inherits:
Object
  • Object
show all
Defined in:
app/message_boxes/nuntius/base_message_box.rb

Overview

Message boxes process inbound messages

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ BaseMessageBox

Returns a new instance of BaseMessageBox.



10
11
12
# File 'app/message_boxes/nuntius/base_message_box.rb', line 10

def initialize(message)
  @message = message
end

Class Attribute Details

.routesObject (readonly)

Returns the value of attribute routes.



25
26
27
# File 'app/message_boxes/nuntius/base_message_box.rb', line 25

def routes
  @routes
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'app/message_boxes/nuntius/base_message_box.rb', line 8

def message
  @message
end

Class Method Details

.deliver(message) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'app/message_boxes/nuntius/base_message_box.rb', line 49

def deliver(message)
  klasses = message_box_for(transport: message.transport.to_sym, provider: message.provider.to_sym)
  klass, method = message_box_for_route(klasses, message)

  if method
    klass.new(message).send(method)
    true
  end
end

.message_box_for(transport: nil, provider: nil) ⇒ Object



59
60
61
62
63
64
# File 'app/message_boxes/nuntius/base_message_box.rb', line 59

def message_box_for(transport: nil, provider: nil)
  result = descendants
  result = result.select { |message_box| message_box.transport == transport } if transport
  result = result.select { |message_box| message_box.provider == provider } if provider
  result
end

.provider(value = nil) ⇒ Object



27
28
29
30
# File 'app/message_boxes/nuntius/base_message_box.rb', line 27

def provider(value = nil)
  @provider = value.to_sym if value
  @provider
end

.route(attribute = :to, test = /.*/, to:) ⇒ Object



37
38
39
40
41
# File 'app/message_boxes/nuntius/base_message_box.rb', line 37

def route(attribute = :to, test = /.*/, to:)
  @routes ||= {}
  @routes[attribute] = {test: test, to: to}
  @routes
end

.settings(hash = nil) ⇒ Object

Defines the settings



44
45
46
47
# File 'app/message_boxes/nuntius/base_message_box.rb', line 44

def settings(hash = nil)
  @settings = hash if hash
  @settings
end

.transport(value = nil) ⇒ Object



32
33
34
35
# File 'app/message_boxes/nuntius/base_message_box.rb', line 32

def transport(value = nil)
  @transport = value.to_sym if value
  @transport
end

Instance Method Details

#mailMail::Message

In case of mail transport mail will return the mail itself, using github.com/mikel/mail For other transports it will return nil.

Returns:

  • (Mail::Message)


17
18
19
20
21
22
# File 'app/message_boxes/nuntius/base_message_box.rb', line 17

def mail
  return nil unless self.class.transport.to_sym == :mail
  return @mail if @mail

  @mail = Mail.new(message.raw_message.download)
end