Class: GitDS::RepoConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/git-ds/config.rb

Overview

Provides access to the repo .git/config file as a hash.

Note that this limits access to a specific section of the config file, named by the parameter ‘section’.

Instance Method Summary collapse

Constructor Details

#initialize(db, section = 'misc') ⇒ RepoConfig

Returns a new instance of RepoConfig.



18
19
20
21
# File 'lib/git-ds/config.rb', line 18

def initialize(db, section='misc')
  @db = db
  @section = clean(section)
end

Instance Method Details

#[](key) ⇒ Object

Return the String value of the variable ‘key’.



40
41
42
43
# File 'lib/git-ds/config.rb', line 40

def [](key)
  rv = @db.repo_config[path(key)]
  rv ? rv : ''
end

#[]=(key, value) ⇒ Object

Writes the String representation of ‘value’ to the variable ‘key’.



48
49
50
# File 'lib/git-ds/config.rb', line 48

def []=(key, value)
  @db.repo_config[path(key)] = value.to_s
end

#clean(str) ⇒ Object

Clean key so it is a valid Config token



26
27
28
# File 'lib/git-ds/config.rb', line 26

def clean(str)
  str.gsub(/[^-[:alnum:]]/, '-')
end

#path(key) ⇒ Object

Return the full path to the variable for ‘key’.



33
34
35
# File 'lib/git-ds/config.rb', line 33

def path(key)
  @section + '.' + clean(key)
end