From 3e02f0c451499c7690ae391f67362c0957b4000c Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 9 Jul 2023 05:49:08 +0100 Subject: [PATCH] apply now handles nested hashes some debug logging added --- lib/voicemeeter/iremote.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/voicemeeter/iremote.rb b/lib/voicemeeter/iremote.rb index 0cbf403..a622d9e 100644 --- a/lib/voicemeeter/iremote.rb +++ b/lib/voicemeeter/iremote.rb @@ -1,10 +1,15 @@ require_relative "errors" +require_relative "meta" +require "easy_logging" module Voicemeeter class IRemote " Common interface between base class and higher classes. " + include EasyLogging + include Meta_Functions + def initialize(remote, i = nil) @remote = remote @index = i @@ -15,15 +20,17 @@ module Voicemeeter end def getter(param, is_string = false) + logger.debug "getter: #{_cmd(param)}" @remote.get(_cmd(param), is_string) end def setter(param, value) + logger.debug "setter: #{_cmd(param)}=#{value}" @remote.set(_cmd(param), value) end def _cmd(param) - param.empty? ? "#{self.identifier}" : "#{self.identifier}.#{param}" + param.empty? ? self.identifier : "#{self.identifier}.#{param}" end def identifier @@ -31,7 +38,18 @@ module Voicemeeter end def apply(params) - params.each { |key, val| self.send(key, val) } + params.each do |key, val| + if val.is_a? Hash + target = self.send(key) + target.apply(val) + else + self.send("#{key}=", val) + end + end + end + + def method_missing(method, *args) + logger.debug "Unknown method #{method} for #{self}." end end end