Class: Philotic::Publisher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Publisher



10
11
12
# File 'lib/philotic/publisher.rb', line 10

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/philotic/publisher.rb', line 7

def connection
  @connection
end

#log_message_handlerObject

Returns the value of attribute log_message_handler.



8
9
10
# File 'lib/philotic/publisher.rb', line 8

def log_message_handler
  @log_message_handler
end

Instance Method Details

#configObject



18
19
20
# File 'lib/philotic/publisher.rb', line 18

def config
  connection.config
end

#loggerObject



14
15
16
# File 'lib/philotic/publisher.rb', line 14

def logger
  connection.logger
end

#normalize_payload_times(payload) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/philotic/publisher.rb', line 35

def normalize_payload_times(payload)
  payload.each do |k, v|
    if v.respond_to?(:utc)
      payload[k] = v.utc
    elsif v.respond_to?(:to_utc)
      payload[k] = v.to_utc
    end
  end
end

#publish(message) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/philotic/publisher.rb', line 22

def publish(message)
   = {headers: message.headers}
  .merge!(message.) if message.
  begin
    message.published = _publish(message.payload, )
  rescue => e
    message.publish_error = e
    logger.error e.message
    raise e if config.raise_error_on_publish
  end
  message
end