check configpath only if configpath exists

override Loader to_s
This commit is contained in:
onyx-and-iris 2023-07-09 21:05:47 +01:00
parent 01314e2e98
commit ca66af7d84

View File

@ -16,12 +16,16 @@ module Voicemeeter
def initialize(kind)
@kind = kind
@configs = Hash.new
logger.debug("generated loader for #{kind}")
end
def to_s
"Loader #{@kind}"
end
protected
def build_reset_profile(overrides = {})
#stree-ignore
def build_reset_profile
aouts = (0...@kind.phys_out).to_h { |i| ["A#{i + 1}", false] }
bouts = (0...@kind.virt_out).to_h { |i| ["B#{i + 1}", false] }
strip_bools = %w[mute mono solo].to_h { |param| [param, false] }
@ -38,15 +42,7 @@ module Voicemeeter
(0...@kind.phys_in).to_h do |i|
[
"strip-#{i}",
{
**aouts,
**bouts,
**strip_bools,
**gain,
**phys_float,
**eq,
**overrides
}
{**aouts,**bouts,**strip_bools,**gain,**phys_float,**eq,**overrides}
]
end
@ -69,25 +65,25 @@ module Voicemeeter
end
def read_from_yml
#stree-ignore
filepaths = [
Pathname.getwd.join("configs", @kind.name.to_s),
Pathname.new(Dir.home).join(
".config",
"voicemeeter-rb",
@kind.name.to_s
),
Pathname.new(Dir.home).join(
"Documents",
"Voicemeeter",
"configs",
@kind.name.to_s
)
Pathname.new(Dir.home).join(".config", "voicemeeter-rb", @kind.name.to_s),
Pathname.new(Dir.home).join("Documents", "Voicemeeter", "configs", @kind.name.to_s)
]
filepaths.each do |pn|
if pn.exist?
logger.debug "checking #{pn} for configs"
configs = pn.glob("*.yml")
configs.each do |config|
filename = config.basename.sub_ext ""
@configs[filename.to_s.to_sym] = YAML.load_file(config)
filename = (config.basename.sub_ext "").to_s.to_sym
if @configs.key? filename
logger.debug "config with name '#{filename}' already in memory, skipping..."
next
end
@configs[filename] = YAML.load_file(config)
logger.info "#{@kind.name}/#{filename} loaded into memory"
end
end
end
end
@ -95,6 +91,7 @@ module Voicemeeter
public
def build
logger.debug "Running #{self}"
@configs[:reset] = build_reset_profile
read_from_yml
end