Class: MultiGit::GitBackend::Config

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/multi_git/git_backend/config.rb

Constant Summary

Constants included from Config

Config::DEFAULT_SCHEMA

Instance Method Summary collapse

Methods included from Config

#[], #default?, #each, #qualified_key, #schema, #schema_for, #section, #split_key, #to_h, #with_schema

Methods included from Utils::AbstractMethods

#abstract

Constructor Details

#initialize(cmd) ⇒ Config

Returns a new instance of Config.



10
11
12
# File 'lib/multi_git/git_backend/config.rb', line 10

def initialize(cmd)
  @cmd = cmd
end

Instance Method Details

#each_explicit_keyObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/multi_git/git_backend/config.rb', line 30

def each_explicit_key
  return to_enum(:each_explicit_key) unless block_given?
  seen = Set.new
  @cmd.('config','--list') do |io|
    io.each_line do |line|
      name, _ = line.split('=',2)
      next if seen.include? name
      seen << name
      yield *split_key(name)
    end
  end
  return self
end

#get(section, subsection, key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/multi_git/git_backend/config.rb', line 14

def get( section, subsection, key )
  s = schema_for(section, subsection, key)
  begin
    # git < 1.8.0 barfs when using --get on a multiply defined 
    #  value, but uses the last value internally.
    # git >= 1.8.0 simply returns the last value
    value = @cmd['config', '--get-all', qualified_key(section, subsection, key)].lines.map(&:chomp)
    value = value.last unless s.list?
    return s.convert(value)
  rescue Cmd::Error::ExitCode1
    return s.default
  rescue Cmd::Error::ExitCode2
    raise Error::DuplicateConfigKey, qualified_key(section, subsection, key)
  end
end