Class: Voicemeeter::Configs::FileReader

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/voicemeeter/configs.rb

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(kind) ⇒ FileReader

Returns a new instance of FileReader.



45
46
47
48
49
50
51
# File 'lib/voicemeeter/configs.rb', line 45

def initialize(kind)
  @configpaths = [
    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)
  ]
end

Instance Method Details

#eachObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/voicemeeter/configs.rb', line 53

def each
  @configpaths.each do |configpath|
    if configpath.exist?
      logger.debug "checking #{configpath} for configs"
      filepaths = configpath.glob("*.{yaml,yml}")
      filepaths.each do |filepath|
        @filename = (filepath.basename.sub_ext "").to_s.to_sym

        yield @filename, YAML.load_file(
          filepath,
          symbolize_names: true
        )
      end
    end
  end
rescue Psych::SyntaxError => e
  logger.error "#{e.class.name}: #{e.message}"
end