Class: Hearken::Preferences
- Inherits:
-
Object
- Object
- Hearken::Preferences
- Includes:
- Paths
- Defined in:
- lib/hearken/preferences.rb
Instance Attribute Summary
Attributes included from Paths
#base_path, #index_path, #preferences_path, #queue_path
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ Preferences
constructor
A new instance of Preferences.
- #persist ⇒ Object
Methods included from Paths
#create_paths, #in_base_dir, #in_queue_dir
Constructor Details
#initialize ⇒ Preferences
Returns a new instance of Preferences.
8 9 10 11 12 13 14 15 |
# File 'lib/hearken/preferences.rb', line 8 def initialize create_paths if File.exists? preferences_path @preferences = YAML.load_file preferences_path else @preferences = {} end end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 |
# File 'lib/hearken/preferences.rb', line 17 def [] key @preferences[key] end |
#[]=(key, value) ⇒ Object
21 22 23 24 |
# File 'lib/hearken/preferences.rb', line 21 def []= key, value @preferences[key] = value persist end |
#persist ⇒ Object
26 27 28 |
# File 'lib/hearken/preferences.rb', line 26 def persist File.open(preferences_path, 'w') {|f| f.puts @preferences.to_yaml} end |