Sha256: 17f87b9c7649d1188890cbc430d4a41c58720d77d2c6e19de8cfd869dce5489c

Contents?: true

Size: 796 Bytes

Versions: 32

Compression:

Stored size: 796 Bytes

Contents

# frozen_string_literal: true

require "dry-transformer"
require "json"

module DjiMqttConnect
  module Thing::Product
    class EventsReplyMarshal < MessageMarshal
      # Renames the method attribute
      class HashTransformer < Dry::Transformer::Pipe
        import Dry::Transformer::HashTransformations

        define! do
          rename_keys _method: :method
        end
      end

      # Converts a message for transmission via MQTT
      def dump(message)
        # Fix up the hash representation
        transformed_message = hash_transformer.call(message)

        # Convert the transformed message into JSON
        JSON.generate(transformed_message)
      end

      private

      def hash_transformer
        @hash_transformer ||= HashTransformer.new
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
dji_mqtt_connect-0.1.24.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.24 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.23.3 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.23.2 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.23.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.23 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.22.2 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.22.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.22 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.21 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.20.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.20 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.19.2 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.19.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.19 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.18 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.17.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.17 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.16.2 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb
dji_mqtt_connect-0.1.16.1 lib/dji_mqtt_connect/marshals/thing/product/events_reply_marshal.rb