class Repokeeper::Config

Constants

CONFIG_DIR
DEFAULT_CONFIG
HOME_DIR

Public Class Methods

default_configuration() click to toggle source
# File lib/repokeeper/config.rb, line 23
def self.default_configuration
  read_configuration_file(DEFAULT_CONFIG)
end
merge_hashes(hash1, hash2) click to toggle source
# 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
new(hash) click to toggle source
# File lib/repokeeper/config.rb, line 7
def initialize(hash)
  @config = hash
end
read(file_path = nil) click to toggle source
# 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

Private Class Methods

read_configuration_file(file_path) click to toggle source
# File lib/repokeeper/config.rb, line 27
def self.read_configuration_file(file_path)
  return {} unless file_path
  YAML.load_file(file_path)
end

Public Instance Methods

for(klass) click to toggle source
# 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