Class: Git::Plan::ConfigFile
- Inherits:
-
Object
- Object
- Git::Plan::ConfigFile
- Includes:
- Singleton
- Defined in:
- lib/git/plan/configfile.rb
Constant Summary collapse
- FILE_NAME =
'.gitpath'.freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #add_command(hash) ⇒ Object
- #delete ⇒ Object
- #empty? ⇒ Boolean
- #get_all ⇒ Object
-
#initialize ⇒ ConfigFile
constructor
A new instance of ConfigFile.
- #load_file ⇒ Object
- #run(command) ⇒ Object
Constructor Details
#initialize ⇒ ConfigFile
11 12 13 14 |
# File 'lib/git/plan/configfile.rb', line 11 def initialize @path = File.join(File.('~'), FILE_NAME) @data = load_file end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/git/plan/configfile.rb', line 8 def path @path end |
Instance Method Details
#add_command(hash) ⇒ Object
16 17 18 19 |
# File 'lib/git/plan/configfile.rb', line 16 def add_command(hash) @data['commands'].merge!(hash) write end |
#delete ⇒ Object
29 30 31 |
# File 'lib/git/plan/configfile.rb', line 29 def delete File.delete(@path) if File.exist?(@path) end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/git/plan/configfile.rb', line 33 def empty? @data == default_structure end |
#get_all ⇒ Object
25 26 27 |
# File 'lib/git/plan/configfile.rb', line 25 def get_all @data['commands'] end |
#load_file ⇒ Object
37 38 39 40 41 42 |
# File 'lib/git/plan/configfile.rb', line 37 def load_file require 'yaml' YAML.load_file(@path) rescue Errno::ENOENT default_structure end |
#run(command) ⇒ Object
21 22 23 |
# File 'lib/git/plan/configfile.rb', line 21 def run(command) @data['commands'][command] end |