Class: Wavesync::Config

Inherits:
Object
  • Object
show all
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].freeze
DEVICE_REQUIRED_KEYS =
%w[name model path].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Config

: (untyped data) -> void



33
34
35
36
37
38
39
40
# File 'lib/wavesync/config.rb', line 33

def initialize(data)
  validate!(data)
  @library = File.expand_path(data['library'])
  @device_configs = data['devices'].each_with_index.map do |device, i|
    validate_device!(device, i)
    { name: device['name'], model: device['model'], path: File.expand_path(device['path']) }
  end
end

Instance Attribute Details

#device_configsObject (readonly)

: Array[{ name: String, model: String, path: String }]



17
18
19
# File 'lib/wavesync/config.rb', line 17

def device_configs
  @device_configs
end

#libraryObject (readonly)

: String



16
17
18
# File 'lib/wavesync/config.rb', line 16

def library
  @library
end

Class Method Details

.load(path = DEFAULT_PATH) ⇒ Object

: (?String path) -> Config



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wavesync/config.rb', line 20

def self.load(path = DEFAULT_PATH)
  expanded = File.expand_path(path)
  begin
    data = YAML.load_file(expanded)
  rescue Errno::ENOENT
    raise ConfigError, "Config file not found: #{path}"
  rescue Psych::SyntaxError => e
    raise ConfigError, "Invalid YAML in config file: #{e.message}"
  end
  new(data)
end