Class: Astrotrain::Mapping::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/astrotrain/mapping/transport.rb

Direct Known Subclasses

HttpPost

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, mapping, recipient) ⇒ Transport

Returns a new instance of Transport.



22
23
24
25
26
27
# File 'lib/astrotrain/mapping/transport.rb', line 22

def initialize(message, mapping, recipient)
  message.body = mapping.find_reply_from(message.body)
  @message     = message
  @mapping     = mapping
  @recipient   = recipient
end

Class Attribute Details

.processingObject

Returns the value of attribute processing.



5
6
7
# File 'lib/astrotrain/mapping/transport.rb', line 5

def processing
  @processing
end

Instance Attribute Details

#mappingObject (readonly)

Returns the value of attribute mapping.



11
12
13
# File 'lib/astrotrain/mapping/transport.rb', line 11

def mapping
  @mapping
end

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/astrotrain/mapping/transport.rb', line 11

def message
  @message
end

Class Method Details

.inherited(child) ⇒ Object

defines custom #process class methods that instantiate the class and calls a #process instance method



45
46
47
48
49
50
51
52
# File 'lib/astrotrain/mapping/transport.rb', line 45

def self.inherited(child)
  super
  class << child
    def process(message, mapping, recipient)
      new(message, mapping, recipient).process
    end
  end
end

.process(message, mapping, recipient) ⇒ Object

process a given message against the mapping. The mapping transport is checked, and the appropirate transport class handles the request.



15
16
17
18
19
20
# File 'lib/astrotrain/mapping/transport.rb', line 15

def self.process(message, mapping, recipient)
  case mapping.transport
    when 'http_post' then HttpPost.process(message, mapping, recipient)
    when 'jabber'    then Jabber.process(message, mapping, recipient)
  end
end

Instance Method Details

#fieldsObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/astrotrain/mapping/transport.rb', line 33

def fields
  @fields ||= begin
    all_emails = @message.recipients - [@recipient]
    f = {:subject => @message.subject, :to => @recipient, :from => @message.sender, :body => @message.body, :emails => all_emails, :html => @message.html}
    @message.headers.each do |key, value|
      f["headers[#{key}]"] = value
    end
    f
  end
end

#processObject

Raises:

  • (UnimplementedError)


29
30
31
# File 'lib/astrotrain/mapping/transport.rb', line 29

def process
  raise UnimplementedError
end