# frozen_string_literal: true module DjiMqttConnect module Utils module MessageParsing private def message_class_for_parsed_message(parsed_message, generic_class) # update_topo => UpdateTopo classified_method = ActiveSupport::Inflector.classify(parsed_message["method"]) # UpdateTopo => DjiMqttConnect::Sys::Product::UpdateTopoStatusMessage module_prefix, joiner, class_suffix = generic_class.name.rpartition("::") message_class_name = [module_prefix, joiner, classified_method, class_suffix].join # Constantize an instance of the message-specific class, or fallback to a generic message ActiveSupport::Inflector.safe_constantize(message_class_name) || generic_class end end end end