Class: Mqttopia::Subscriptions::Redirect

Inherits:
Object
  • Object
show all
Defined in:
lib/mqttopia/subscriptions/redirect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic_name:, payload:) ⇒ Redirect



16
17
18
19
20
# File 'lib/mqttopia/subscriptions/redirect.rb', line 16

def initialize(topic_name:, payload:)
  @topic_name = topic_name
  @payload = payload
  @debugging = Mqttopia.debugging
end

Instance Attribute Details

#debuggingObject (readonly)

Returns the value of attribute debugging.



14
15
16
# File 'lib/mqttopia/subscriptions/redirect.rb', line 14

def debugging
  @debugging
end

#payloadObject (readonly)

Returns the value of attribute payload.



14
15
16
# File 'lib/mqttopia/subscriptions/redirect.rb', line 14

def payload
  @payload
end

#topic_nameObject (readonly)

Returns the value of attribute topic_name.



14
15
16
# File 'lib/mqttopia/subscriptions/redirect.rb', line 14

def topic_name
  @topic_name
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mqttopia/subscriptions/redirect.rb', line 22

def call
  Mqttopia::Topics::Services::KEYS.each do |key, value|
    next unless topic_name.match?(value[:regex])

    return {
      event: key&.to_s,
      data: value[:service].safe_constantize.call(
        topic_name,
        payload,
        { serializer: value[:serializer] }
      )
    }
  end

  Mqttopia::Logger.warn "No matching topic found for #{topic_name}" if debugging
end