Class: Segue::Settings
- Inherits:
-
Object
- Object
- Segue::Settings
- Defined in:
- lib/segue/settings.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#preferences ⇒ Object
readonly
Returns the value of attribute preferences.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(path) ⇒ Settings
constructor
A new instance of Settings.
- #persist ⇒ Object
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.(path) FileUtils.mkdir_p File.dirname(@path) @preferences = File.exist?(@path) ? YAML.load_file(@path) : {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/segue/settings.rb', line 8 def path @path end |
#preferences ⇒ Object (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 |
#persist ⇒ Object
25 26 27 |
# File 'lib/segue/settings.rb', line 25 def persist File.open(path, "w") { |f| f.puts preferences.to_yaml } end |