Sha256: a51666abb1727b34faa6a1a9a9fa7035dbad37b95c79a5902600eaf2e7ede833

Contents?: true

Size: 793 Bytes

Versions: 30

Compression:

Stored size: 793 Bytes

Contents

# frozen_string_literal: true

require "dry-transformer"
require "json"

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

30 entries across 30 versions & 1 rubygems

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