Sha256: d1acbeeb378cf205c7112455e0f761b9f67ae09f04b6e5c820a6ced5ad21e23d

Contents?: true

Size: 795 Bytes

Versions: 6

Compression:

Stored size: 795 Bytes

Contents

# frozen_string_literal: true

require "dry-transformer"
require "json"

module DjiMqttConnect
  module Thing::Product
    class StateReplyMarshal < 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

6 entries across 6 versions & 1 rubygems

Version Path
dji_mqtt_connect-0.1.24.1 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb
dji_mqtt_connect-0.1.24 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb
dji_mqtt_connect-0.1.23.3 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb
dji_mqtt_connect-0.1.23.2 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb
dji_mqtt_connect-0.1.23.1 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb
dji_mqtt_connect-0.1.23 lib/dji_mqtt_connect/marshals/thing/product/state_reply_marshal.rb