Sha256: c0cac4474402196c4a5e9b52a620597aa1ea70f88b5884c00d6d4adf4535a236
Contents?: true
Size: 1.71 KB
Versions: 2
Compression:
Stored size: 1.71 KB
Contents
# frozen_string_literal: true # Volay module module Volay # Config class class Config attr_reader :logger, :mixer, :options ## # Get option # # @return [Mixed] # def self.init_config File.write(config_file, '') unless File.exist?(config_file) logger.level = get(:log_level) end ## # Get option # # @return [Mixed] # def self.get(option) @options ||= {} @options[option.to_sym] if @options.key?(option.to_sym) end ## # Set option # # @param [String|Symbol] option Option key # @param [Mixed] value Option value # def self.set(option, value) @options ||= {} @options[option.to_sym] = value end ## # Get config file # # @return [String] # def self.config_file File.expand_path('~/.volay') end ## # Get logger # # @return [Logger] # def self.logger @logger ||= Logger.new(STDOUT) end ## # Initialize mixer for controlling volume # def self.mixer raise MixerNotFound unless which('pacmd') @mixer ||= Volay::Mixer::Pulse.new end ## # Cross-platform way of finding an executable in the $PATH. # # Example: # which('ruby') #=> /usr/bin/ruby # which('foo') #=> nil # # @param [String] cmd Which command # @return [String|NilClass] # def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
volay-2.2.0 | lib/volay/config.rb |
volay-2.1.0 | lib/volay/config.rb |