Class: Preferences
- Inherits:
-
Object
show all
- Defined in:
- lib/models/preferences.rb
Constant Summary
collapse
- @@primary_defaults =
{
editor: 'vim',
notes_dir: File.expand_path('~/Notes')
}
- @@aux_defaults =
{
extension: 'txt'
}
- @@defaults =
@@aux_defaults.merge(@@primary_defaults)
- @@prefs_file =
File.expand_path('~/.peter-notes.yml')
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(prefs = nil) ⇒ Preferences
Returns a new instance of Preferences.
28
29
30
|
# File 'lib/models/preferences.rb', line 28
def initialize(prefs=nil)
@preferences = load_preferences(prefs)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attribute) ⇒ Object
36
37
38
39
|
# File 'lib/models/preferences.rb', line 36
def method_missing(attribute)
return @preferences[attribute] if @preferences.has_key?(attribute)
super
end
|
Instance Attribute Details
#preferences ⇒ Object
Returns the value of attribute preferences.
4
5
6
|
# File 'lib/models/preferences.rb', line 4
def preferences
@preferences
end
|
Class Method Details
.defaults ⇒ Object
16
17
18
|
# File 'lib/models/preferences.rb', line 16
def self.defaults
@@defaults
end
|
.defaults_yaml ⇒ Object
24
25
26
|
# File 'lib/models/preferences.rb', line 24
def self.defaults_yaml
@@primary_defaults.to_yaml
end
|
.prefs_file ⇒ Object
20
21
22
|
# File 'lib/models/preferences.rb', line 20
def self.prefs_file
@@prefs_file
end
|
.write_yaml_defaults ⇒ Object
32
33
34
|
# File 'lib/models/preferences.rb', line 32
def self.write_yaml_defaults
File.write(@@prefs_file, self.defaults_yaml)
end
|