Class: Repokeeper::Config

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

Constant Summary collapse

HOME_DIR =
File.expand_path('../../../', __FILE__)
CONFIG_DIR =
File.join(HOME_DIR, 'config')
DEFAULT_CONFIG =
File.join(CONFIG_DIR, 'default.yml')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Config

Returns a new instance of Config.



7
8
9
# File 'lib/repokeeper/config.rb', line 7

def initialize(hash)
  @config = hash
end

Class Method Details

.default_configurationObject



23
24
25
# File 'lib/repokeeper/config.rb', line 23

def self.default_configuration
  read_configuration_file(DEFAULT_CONFIG)
end

.merge_hashes(hash1, hash2) ⇒ Object



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

def self.merge_hashes(hash1, hash2)
  hash1.merge(hash2) do |_, oldval, newval|
    old_hash = oldval || {}
    new_hash = newval || {}

    old_hash.merge(new_hash)
  end
end

.read(file_path = nil) ⇒ Object



17
18
19
20
21
# File 'lib/repokeeper/config.rb', line 17

def self.read(file_path = nil)
  config_file = read_configuration_file(file_path)
  config = merge_hashes(default_configuration, config_file)
  new(config)
end

Instance Method Details

#for(klass) ⇒ Object



11
12
13
14
15
# File 'lib/repokeeper/config.rb', line 11

def for(klass)
  key = klass.name.split('::').last
             .gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
  @config[key]
end