Class: Git::Superproject::Config
- Inherits:
-
Object
- Object
- Git::Superproject::Config
- Defined in:
- lib/git/superproject.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(name, *repos) ⇒ Object
-
#initialize(key_value_pairs) ⇒ Config
constructor
A new instance of Config.
- #list(name) ⇒ Object
- #remove(name, *repos) ⇒ Object
- #save(file) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(key_value_pairs) ⇒ Config
Returns a new instance of Config.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git/superproject.rb', line 28 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
20 21 22 23 24 25 26 |
# File 'lib/git/superproject.rb', line 20 def self.from(file) new( `git config --file #{file} --list` .split($RS) .map(&:strip) ) end |
Instance Method Details
#add(name, *repos) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/git/superproject.rb', line 43 def add(name, *repos) repos.each do |repo| add_to(name, repo) end list(name) end |
#list(name) ⇒ Object
39 40 41 |
# File 'lib/git/superproject.rb', line 39 def list(name) @superprojects[name].to_a.sort end |
#remove(name, *repos) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/git/superproject.rb', line 50 def remove(name, *repos) repos.each do |repo| remove_from(name, repo) end list(name) end |
#save(file) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/git/superproject.rb', line 57 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_json ⇒ Object
69 70 71 |
# File 'lib/git/superproject.rb', line 69 def to_json @superprojects.to_json end |