no need to pass loader reference to FileReader

This commit is contained in:
onyx-and-iris 2023-08-02 13:01:46 +01:00
parent fdfadaafac
commit bb62f01b11

View File

@ -51,8 +51,7 @@ module Voicemeeter
class FileReader class FileReader
include Logging include Logging
def initialize(loader, kind) def initialize(kind)
@loader = loader
@configpaths = [ @configpaths = [
Pathname.getwd.join("configs", kind.name.to_s), 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(".config", "voicemeeter-rb", kind.name.to_s),
@ -90,13 +89,22 @@ module Voicemeeter
@configs = Hash.new do |hash, key| @configs = Hash.new do |hash, key|
raise Errors::VMError.new "unknown config #{key}. known configs: #{hash.keys}" raise Errors::VMError.new "unknown config #{key}. known configs: #{hash.keys}"
end end
@filereader = FileReader.new(self, kind) @filereader = FileReader.new(kind)
end end
def to_s def to_s
"Loader #{@kind}" "Loader #{@kind}"
end end
def run
logger.debug "Running #{self}"
configs[:reset] = TOMLStrBuilder.run(@kind)
@filereader.each do |identifier, data|
register(identifier, data)
end
self
end
private def register(identifier, data) private def register(identifier, data)
if configs.key? identifier if configs.key? identifier
logger.debug "config with name '#{identifier}' already in memory, skipping..." logger.debug "config with name '#{identifier}' already in memory, skipping..."
@ -106,15 +114,6 @@ module Voicemeeter
configs[identifier] = data configs[identifier] = data
logger.info "#{@kind.name}/#{identifier} loaded into memory" logger.info "#{@kind.name}/#{identifier} loaded into memory"
end end
def run
logger.debug "Running #{self}"
configs[:reset] = TOMLStrBuilder.run(@kind)
@filereader.each do |identifier, data|
register(identifier, data)
end
self
end
end end
def get(kind_id) def get(kind_id)