Class: Git::Superproject::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/git/superproject.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_value_pairs) ⇒ Config

Returns a new instance of Config.



35
36
37
38
39
40
41
42
43
44
# File 'lib/git/superproject.rb', line 35

def initialize(key_value_pairs)
  @superprojects = Hash.new do |superprojects, name|
    superprojects[name] = Set.new # guarantee uniqueness
  end

  key_value_pairs.each do |key_value|
    key, value = key_value.split('=')
    process(key, value)
  end
end

Class Method Details

.from(file) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/git/superproject.rb', line 27

def self.from(file)
  new(
    `git config --file #{file} --list`
    .split($RS)
    .map(&:strip)
  )
end

Instance Method Details

#add(name, *repos) ⇒ Object



50
51
52
53
54
# File 'lib/git/superproject.rb', line 50

def add(name, *repos)
  repos.each do |repo|
    add_to(name, repo)
  end
end

#list(name) ⇒ Object



46
47
48
# File 'lib/git/superproject.rb', line 46

def list(name)
  log_to($stdout, name)
end

#remove(name, *repos) ⇒ Object



56
57
58
59
60
# File 'lib/git/superproject.rb', line 56

def remove(name, *repos)
  repos.each do |repo|
    remove_from(name, repo)
  end
end

#save(file) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/git/superproject.rb', line 62

def save(file)
  # create backup of original file
  FileUtils.mv(file, "#{file}~") if File.exist? file

  @superprojects.keys.each do |name|
    write_to(file, name)
  end

  # copy across all the comments from the original file
  `egrep '^# ' "#{file}~" >> "#{file}"`
end

#to_jsonObject



74
75
76
# File 'lib/git/superproject.rb', line 74

def to_json
  @superprojects.to_json
end