Sha256: 6a883890caf47f110e91798929a40be74ef7848d015323e86e47e8a4c7f31ea0
Contents?: true
Size: 1.08 KB
Versions: 9
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require "dry-struct" require "dry-transformer" require "json" module DjiMqttConnect module Thing::Product class StateMarshal < MessageMarshal include Utils::MessageParsing # Rename pesky `method` argument to `_method` and makes a copy of the raw data class AttributeTransformer < Dry::Transformer::Pipe import Dry::Transformer::HashTransformations define! do copy_keys "data" => "_data" end end # Attempts to look a the method attribute, and builds a specific Message class for the message def load(raw_message) # Parse the message from JSON parsed_message = parse_json(raw_message) # Transform the message transformed_message = attribute_transformer.call(parsed_message) # Build an instance of the class, or a generic message from the current class build_message(StateMessage, transformed_message) end private def attribute_transformer @attribute_transformer ||= AttributeTransformer.new end end end end
Version data entries
9 entries across 9 versions & 1 rubygems