Class: GitBundle::BranchConfig
- Inherits:
-
Object
- Object
- GitBundle::BranchConfig
show all
- Includes:
- Console
- Defined in:
- lib/git_bundle/branch_config.rb
Constant Summary
collapse
- BRANCH_CONFIG_FILE =
'.gitb.yml'
Constants included
from Console
Console::COLORS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Console
#clear_line, #parallel, #puts_attention, #puts_error, #puts_heading, #puts_prompt, #puts_repo_heading, #puts_repo_heading_switch, #puts_stay_on_line, #puts_wait_line
Constructor Details
#initialize(filename = nil) ⇒ BranchConfig
Returns a new instance of BranchConfig.
8
9
10
|
# File 'lib/git_bundle/branch_config.rb', line 8
def initialize(filename = nil)
@filename = filename || BRANCH_CONFIG_FILE
end
|
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
6
7
8
|
# File 'lib/git_bundle/branch_config.rb', line 6
def filename
@filename
end
|
Instance Method Details
#changed? ⇒ Boolean
25
26
27
|
# File 'lib/git_bundle/branch_config.rb', line 25
def changed?
current != read
end
|
#current ⇒ Object
16
17
18
19
|
# File 'lib/git_bundle/branch_config.rb', line 16
def current
return @current if defined?(@current)
@current = read
end
|
#path ⇒ Object
12
13
14
|
# File 'lib/git_bundle/branch_config.rb', line 12
def path
File.join(Dir.pwd, filename)
end
|
#read ⇒ Object
21
22
23
|
# File 'lib/git_bundle/branch_config.rb', line 21
def read
File.exists?(path) ? YAML.load_file(path) || {} : nil
end
|
#save ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/git_bundle/branch_config.rb', line 29
def save
File.open(path, 'w') {|file| file.write(current.to_yaml.lines[1..-1].join)}
if File.exists?(path)
puts "\t#{colorize('update', 34, bold: true)}\t#{filename}"
else
puts "\t#{colorize('create', 32, bold: true)}\t#{filename}"
end
end
|