Class: AudioAddict::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_addict/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pathObject



45
46
47
# File 'lib/audio_addict/config.rb', line 45

def path
  @path ||= ENV.fetch('AUDIO_ADDICT_CONFIG_PATH', default_path)
end

Class Method Details

.default_pathObject



49
50
51
# File 'lib/audio_addict/config.rb', line 49

def default_path
  "#{Dir.home}/.audio_addict/config"
end

.delete(*keys) ⇒ Object



21
22
23
# File 'lib/audio_addict/config.rb', line 21

def delete(*keys)
  keys.each { |key| properties.delete key.to_sym }
end

.has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/audio_addict/config.rb', line 29

def has_key?(key)
  properties.has_key? key.to_sym
end

.method_missing(name, *args) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/audio_addict/config.rb', line 8

def method_missing(name, *args, &)
  if name.to_s.end_with? '='
    name = name[0..-2].to_sym
    properties[name] = args.first
  else
    properties[name]
  end
end

.propertiesObject



33
34
35
# File 'lib/audio_addict/config.rb', line 33

def properties
  @properties ||= properties!
end

.properties!Object



37
38
39
# File 'lib/audio_addict/config.rb', line 37

def properties!
  File.exist?(path) ? YAML.load_file(path) : {}
end

.respond_to_missing?(*_args) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to_missing?(*_args)
  true
end

.saveObject



25
26
27
# File 'lib/audio_addict/config.rb', line 25

def save
  File.deep_write path, sorted_properties.to_yaml
end

.sorted_propertiesObject



41
42
43
# File 'lib/audio_addict/config.rb', line 41

def sorted_properties
  properties.sort.to_h
end