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].freeze
- DEVICE_REQUIRED_KEYS =
%w[name model path].freeze
Instance Attribute Summary collapse
-
#device_configs ⇒ Object
readonly
Returns the value of attribute device_configs.
-
#library ⇒ Object
readonly
Returns the value of attribute library.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(data) ⇒ Config
Returns a new instance of Config.
29 30 31 32 33 34 35 36 |
# File 'lib/wavesync/config.rb', line 29 def initialize(data) validate!(data) @library = File.(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.(device['path']) } end end |
Instance Attribute Details
#device_configs ⇒ Object (readonly)
Returns the value of attribute device_configs.
15 16 17 |
# File 'lib/wavesync/config.rb', line 15 def device_configs @device_configs end |
#library ⇒ Object (readonly)
Returns the value of attribute library.
15 16 17 |
# File 'lib/wavesync/config.rb', line 15 def library @library end |
Class Method Details
.load(path = DEFAULT_PATH) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/wavesync/config.rb', line 17 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 |