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



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

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

Class Method Details

.default_pathObject



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

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

.delete(*keys) ⇒ Object



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

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

.has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.method_missing(name, *args, &_blk) ⇒ Object



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

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

.propertiesObject



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

def properties
  @properties ||= properties!
end

.properties!Object



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

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

.saveObject



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

def save
  File.deep_write path, sorted_properties.to_yaml
end

.sorted_propertiesObject



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

def sorted_properties
  properties.sort.to_h
end