Class: Git::Plan::ConfigFile

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/git/plan/configfile.rb

Constant Summary collapse

FILE_NAME =
'.gitpath'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigFile



11
12
13
14
# File 'lib/git/plan/configfile.rb', line 11

def initialize
  @path = File.join(File.expand_path('~'), FILE_NAME)
  @data = load_file
end

Instance Attribute Details

#pathObject

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

#deleteObject



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_allObject



25
26
27
# File 'lib/git/plan/configfile.rb', line 25

def get_all
  @data['commands']
end

#load_fileObject



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