Class: Wavesync::Config
- Inherits:
-
Object
- Object
- Wavesync::Config
- Defined in:
- lib/wavesync/config.rb
Constant Summary collapse
- DEFAULT_PATH =
File.join(Dir.home, 'wavesync.yml')
- SUPPORTED_KEYS =
%w[library devices].freeze
- DEVICE_SUPPORTED_KEYS =
%w[name model path transport mp3_bitrate].freeze
- DEVICE_REQUIRED_KEYS =
%w[name model path].freeze
- SUPPORTED_TRANSPORTS =
%w[filesystem mtp].freeze
- SUPPORTED_MP3_BITRATES =
[96, 128, 160, 192, 256, 320].freeze
- DEFAULT_MP3_BITRATE =
192
Instance Attribute Summary collapse
-
#device_configs ⇒ Object
readonly
: Array[{ name: String, model: String, path: String, transport: String, mp3_bitrate: Integer }].
-
#library ⇒ Object
readonly
: String.
Class Method Summary collapse
-
.load(path = DEFAULT_PATH) ⇒ Object
: (?String path) -> Config.
Instance Method Summary collapse
-
#initialize(data) ⇒ Config
constructor
: (untyped data) -> void.
Constructor Details
#initialize(data) ⇒ Config
: (untyped data) -> void
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wavesync/config.rb', line 36 def initialize(data) validate!(data) @library = File.(data['library']) @device_configs = data['devices'].each_with_index.map do |device, i| validate_device!(device, i) transport = device['transport'] || 'filesystem' path = transport == 'filesystem' ? File.(device['path']) : device['path'] { name: device['name'], model: device['model'], path: path, transport: transport, mp3_bitrate: device['mp3_bitrate'] || DEFAULT_MP3_BITRATE } end end |
Instance Attribute Details
#device_configs ⇒ Object (readonly)
: Array[{ name: String, model: String, path: String, transport: String, mp3_bitrate: Integer }]
20 21 22 |
# File 'lib/wavesync/config.rb', line 20 def device_configs @device_configs end |
#library ⇒ Object (readonly)
: String
19 20 21 |
# File 'lib/wavesync/config.rb', line 19 def library @library end |
Class Method Details
.load(path = DEFAULT_PATH) ⇒ Object
: (?String path) -> Config
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wavesync/config.rb', line 23 def self.load(path = DEFAULT_PATH) = File.(path) begin data = YAML.load_file() rescue Errno::ENOENT raise ConfigError, "Config file not found: #{path}" rescue Psych::SyntaxError => e raise ConfigError, "Invalid YAML in config file: #{e.}" end new(data) end |