Class: ConfigManager
- Inherits:
-
Object
- Object
- ConfigManager
- Defined in:
- lib/gito/config_manager.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize ⇒ ConfigManager
constructor
A new instance of ConfigManager.
- #write(config) ⇒ Object
- #write_editor(new_editor) ⇒ Object
Constructor Details
#initialize ⇒ ConfigManager
Returns a new instance of ConfigManager.
5 6 7 8 9 10 11 |
# File 'lib/gito/config_manager.rb', line 5 def initialize SafeYAML::OPTIONS[:default_mode] = :safe SafeYAML::OPTIONS[:deserialize_symbols] = true @conf_path = "#{Dir.home}/.gito.yml" @default_config = {"editor": "subl"} end |
Instance Method Details
#get ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gito/config_manager.rb', line 24 def get if File.exists? (@conf_path) file = File.open(@conf_path, 'rb') contents = file.read config = YAML.load(contents, :safe => true) else write @default_config config = @default_config end config end |
#write(config) ⇒ Object
19 20 21 22 |
# File 'lib/gito/config_manager.rb', line 19 def write(config) new_config = config.to_yaml File.open(@conf_path, 'w') { |file| file.write(new_config)} end |
#write_editor(new_editor) ⇒ Object
13 14 15 16 17 |
# File 'lib/gito/config_manager.rb', line 13 def write_editor(new_editor) current_config = get current_config[:editor] = new_editor write(current_config) end |