Class: HermesMessengerOfTheGods::Endpoints::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_OPTIONS, Base::DEFAULT_RETRYS

Instance Attribute Summary collapse

Attributes inherited from Base

#endpoint, #errors, #name, #options, #result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#_transmit_payload, #backoff, #bulk_dispatch!, #dispatch, #dispatch!, #fetch_option, #handle_failure, #handle_success, #initialize, #max_retries, #retry_from, #teardown, #transform_message

Constructor Details

This class inherits a constructor from HermesMessengerOfTheGods::Endpoints::Base

Instance Attribute Details

#on_receiveObject

Returns the value of attribute on_receive.



16
17
18
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 16

def on_receive
  @on_receive
end

Class Method Details

.clear_queue!Object



7
8
9
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 7

def clear_queue!
  @received = nil
end

.receivedObject



11
12
13
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 11

def received
  @received ||= Hash.new { |h, k| h[k] = [] }
end

Instance Method Details

#bulk_transmit(payloads) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 30

def bulk_transmit(payloads)
  payloads.each do |msg|
    pub_opts = fetch_option(:publish_options, msg[:raw_message]) || {}

    new_msg = { message: msg[:message], options: msg[:options].merge(pub_opts) }
    received << new_msg
    on_receive&.call(new_msg)
    "Recorded msg ##{self.class.received[endpoint].length} for #{endpoint}"
  end
end

#receivedObject



18
19
20
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 18

def received
  self.class.received[endpoint]
end

#to_transmit_payload(message, raw_message, dispatch_options = {}) ⇒ Object



22
23
24
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 22

def to_transmit_payload(message, raw_message, dispatch_options = {})
  { message: message, raw_message: raw_message, options: dispatch_options }
end

#transmit(payload) ⇒ Object



26
27
28
# File 'lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb', line 26

def transmit(payload)
  bulk_transmit([payload])
end