Class: Songbirdsh::Preferences

Inherits:
Object
  • Object
show all
Defined in:
lib/songbirdsh/preferences.rb

Instance Method Summary collapse

Constructor Details

#initializePreferences

Returns a new instance of Preferences.



3
4
5
6
7
8
9
10
# File 'lib/songbirdsh/preferences.rb', line 3

def initialize
  @preference_path = home_path '.songbirdsh'
  if File.exists? @preference_path
    @preferences = YAML.load File.read(@preference_path)
  else
    @preferences = {}
  end
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/songbirdsh/preferences.rb', line 16

def [] key
  @preferences[key]
end

#[]=(key, value) ⇒ Object



20
21
22
23
# File 'lib/songbirdsh/preferences.rb', line 20

def []= key, value
  @preferences[key] = value
  persist
end

#home_path(*paths) ⇒ Object



12
13
14
# File 'lib/songbirdsh/preferences.rb', line 12

def home_path *paths
  File.join File.expand_path('~'), *paths
end

#persistObject



25
26
27
# File 'lib/songbirdsh/preferences.rb', line 25

def persist
  File.open(@preference_path, 'w') {|f| f.puts @preferences.to_yaml}
end