Class: Config::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/config/stack.rb

Constant Summary collapse

GLOBAL_CONFIG =
File.expand_path("~/.gitconfig")
SYSTEM_CONFIG =
"/etc/gitconfig"

Instance Method Summary collapse

Constructor Details

#initialize(git_path) ⇒ Stack

Returns a new instance of Stack.



10
11
12
13
14
15
16
# File 'lib/config/stack.rb', line 10

def initialize(git_path)
  @configs = {
    :local  => Config.new(git_path.join("config")),
    :global => Config.new(Pathname.new(GLOBAL_CONFIG)),
    :system => Config.new(Pathname.new(SYSTEM_CONFIG))
  }
end

Instance Method Details

#file(name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/config/stack.rb', line 18

def file(name)
  if @configs.has_key?(name)
    @configs[name]
  else
    Config.new(Pathname.new(name))
  end
end

#get(key) ⇒ Object



30
31
32
# File 'lib/config/stack.rb', line 30

def get(key)
  get_all(key).last
end

#get_all(key) ⇒ Object



34
35
36
37
38
39
# File 'lib/config/stack.rb', line 34

def get_all(key)
  [:system, :global, :local].flat_map do |name|
    @configs[name].open
    @configs[name].get_all(key)
  end
end

#openObject



26
27
28
# File 'lib/config/stack.rb', line 26

def open
  @configs.each_value(&:open)
end