Class: Artery::Subscription::IncomingMessage
- Inherits:
-
Object
- Object
- Artery::Subscription::IncomingMessage
- Defined in:
- lib/artery/subscription/incoming_message.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#from ⇒ Object
Returns the value of attribute from.
-
#from_uri ⇒ Object
Returns the value of attribute from_uri.
-
#options ⇒ Object
Returns the value of attribute options.
-
#reply ⇒ Object
Returns the value of attribute reply.
-
#subscription ⇒ Object
Returns the value of attribute subscription.
Instance Method Summary collapse
- #action ⇒ Object
-
#enrich_data ⇒ Object
rubocop:disable Metrics/AbcSize.
- #from_updates? ⇒ Boolean
- #has_index? ⇒ Boolean
- #index ⇒ Object
-
#initialize(subscription, data, reply, from, **options) ⇒ IncomingMessage
constructor
A new instance of IncomingMessage.
- #inspect ⇒ Object
- #previous_index ⇒ Object
- #update_by_us? ⇒ Boolean
Constructor Details
#initialize(subscription, data, reply, from, **options) ⇒ IncomingMessage
Returns a new instance of IncomingMessage.
8 9 10 11 12 13 14 15 16 |
# File 'lib/artery/subscription/incoming_message.rb', line 8 def initialize(subscription, data, reply, from, **) @subscription = subscription @data = data @attributes = data[:attributes] @reply = reply @from = from @from_uri = Routing.uri(@from) @options = end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def data @data end |
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def from @from end |
#from_uri ⇒ Object
Returns the value of attribute from_uri.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def from_uri @from_uri end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def @options end |
#reply ⇒ Object
Returns the value of attribute reply.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def reply @reply end |
#subscription ⇒ Object
Returns the value of attribute subscription.
6 7 8 |
# File 'lib/artery/subscription/incoming_message.rb', line 6 def subscription @subscription end |
Instance Method Details
#action ⇒ Object
18 19 20 |
# File 'lib/artery/subscription/incoming_message.rb', line 18 def action from_uri.action end |
#enrich_data ⇒ Object
rubocop:disable Metrics/AbcSize
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/artery/subscription/incoming_message.rb', line 42 def enrich_data # rubocop:disable Metrics/AbcSize # NO enrich needed as we already have message with attributes if @attributes yield @attributes return end get_uri = Routing.uri service: from_uri.service, model: from_uri.model, plural: true, action: :get get_data = { uuid: data[:uuid], representation: subscription.representation_name } Artery.request get_uri.to_route, get_data do |on| on.success do |attributes| yield attributes rescue Exception => e # rubocop:disable Lint/RescueException error = Error.new("Error in subscription handler: #{e.inspect}", original_exception: e, subscription: { subscriber: subscription.subscriber.to_s, data: data.to_json, route: from }, request: { data: get_data.to_json, route: get_uri.to_route }, response: attributes.to_json) Artery.handle_error error end on.error do |e| if e. == 'not_found' yield(:not_found) else error = Error.new( "Failed to get #{get_uri.model} from #{get_uri.service} with uuid='#{data[:uuid]}': #{e.}", **e.artery_context, subscription: { subscriber: subscription.subscriber.to_s, data: data.to_json, route: from_uri.to_route } ) Artery.handle_error error end end end end |
#from_updates? ⇒ Boolean
34 35 36 |
# File 'lib/artery/subscription/incoming_message.rb', line 34 def from_updates? [:from_updates] end |
#has_index? ⇒ Boolean
30 31 32 |
# File 'lib/artery/subscription/incoming_message.rb', line 30 def has_index? index.positive? end |
#index ⇒ Object
22 23 24 |
# File 'lib/artery/subscription/incoming_message.rb', line 22 def index data[:_index].to_i end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/artery/subscription/incoming_message.rb', line 93 def inspect "<#{from}> <#{reply}> #{data}".inspect end |
#previous_index ⇒ Object
26 27 28 |
# File 'lib/artery/subscription/incoming_message.rb', line 26 def previous_index data[:_previous_index].to_i end |
#update_by_us? ⇒ Boolean
38 39 40 |
# File 'lib/artery/subscription/incoming_message.rb', line 38 def update_by_us? data[:updated_by_service].to_s == Artery.service_name.to_s end |