Class: Segue::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/segue/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Settings

Returns a new instance of Settings.



10
11
12
13
14
# File 'lib/segue/settings.rb', line 10

def initialize(path)
  @path = File.expand_path(path)
  FileUtils.mkdir_p File.dirname(@path)
  @preferences = File.exist?(@path) ? YAML.load_file(@path) : {}
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/segue/settings.rb', line 8

def path
  @path
end

#preferencesObject (readonly)

Returns the value of attribute preferences.



8
9
10
# File 'lib/segue/settings.rb', line 8

def preferences
  @preferences
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/segue/settings.rb', line 16

def [](key)
  preferences[key]
end

#[]=(key, value) ⇒ Object



20
21
22
23
# File 'lib/segue/settings.rb', line 20

def []=(key, value)
  preferences[key] = value
  persist
end

#persistObject



25
26
27
# File 'lib/segue/settings.rb', line 25

def persist
  File.open(path, "w") { |f| f.puts preferences.to_yaml }
end