Class: GitBundle::BranchConfig

Inherits:
Object
  • Object
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_diverged_repos, #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

#filenameObject (readonly)

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

#branch(repo_name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/git_bundle/branch_config.rb', line 30

def branch(repo_name)
  source = current[repo_name]
  if source&.include?(' ')
    source.split(' ').last
  else
    source
  end
end

#changed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/git_bundle/branch_config.rb', line 43

def changed?
  current != read
end

#currentObject



16
17
18
19
# File 'lib/git_bundle/branch_config.rb', line 16

def current
  return @current if defined?(@current)
  @current = read
end

#pathObject



12
13
14
# File 'lib/git_bundle/branch_config.rb', line 12

def path
  File.join(Dir.pwd, filename)
end

#readObject



39
40
41
# File 'lib/git_bundle/branch_config.rb', line 39

def read
  File.exists?(path) ? YAML.load_file(path) || {} : nil
end

#remote(repo_name) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/git_bundle/branch_config.rb', line 21

def remote(repo_name)
  source = current[repo_name]
  if source.include?(' ')
    source.split(' ').first
  else
    nil
  end
end

#saveObject



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/git_bundle/branch_config.rb', line 47

def save
  if changed?
    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
  else
    puts "\t#{colorize('identical', 34, bold: true)}\t#{filename}"
  end
end