Class: Preferences

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

Constant Summary collapse

@@home_dir =
ENV['HOME']
@@defaults =
{
  editor: 'vim',
  notes_dir: "#{@@home_dir}/Notes"
}
@@prefs_file =
"#{@@home_dir}/.peter-notes.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefs = nil) ⇒ Preferences



25
26
27
28
29
30
# File 'lib/models/preferences.rb', line 25

def initialize(prefs=nil)
  @preferences = prefs || load_preferences
  @preferences[:notes_dir] = File.expand_path(@preferences[:notes_dir])
  @editor = @preferences[:editor]
  @notes_dir = @preferences[:notes_dir]
end

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



4
5
6
# File 'lib/models/preferences.rb', line 4

def editor
  @editor
end

#notes_dirObject (readonly)

Returns the value of attribute notes_dir.



4
5
6
# File 'lib/models/preferences.rb', line 4

def notes_dir
  @notes_dir
end

#preferencesObject (readonly)

Returns the value of attribute preferences.



4
5
6
# File 'lib/models/preferences.rb', line 4

def preferences
  @preferences
end

Class Method Details

.defaultsObject



13
14
15
# File 'lib/models/preferences.rb', line 13

def self.defaults
  @@defaults
end

.defaults_yamlObject



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

def self.defaults_yaml
  @@defaults.to_yaml
end

.prefs_fileObject



17
18
19
# File 'lib/models/preferences.rb', line 17

def self.prefs_file
  @@prefs_file
end

.write_yaml_defaultsObject



32
33
34
# File 'lib/models/preferences.rb', line 32

def self.write_yaml_defaults
  File.write(@@prefs_file, self.defaults_yaml)
end