class FlashFlow::Config

Constants

ATTRIBUTES

Attributes

logger[R]

Public Class Methods

configuration() click to toggle source
# File lib/flash_flow/config.rb, line 26
def self.configuration
  raise NotYetConfigured unless instance.instance_variable_get(:@configured)
  instance
end
configure!(config_file) click to toggle source
# File lib/flash_flow/config.rb, line 31
def self.configure!(config_file)
  raise AlreadyConfigured if instance.instance_variable_get(:@configured)

  template = ERB.new File.read(config_file)
  yaml = YAML.load template.result(binding)
  config = defaults.merge(symbolize_keys!(yaml))

  missing_attrs = []
  ATTRIBUTES.each do |attr_name|
    missing_attrs << attr_name unless config.has_key?(attr_name)
    instance.instance_variable_set("@#{attr_name}", config[attr_name])
  end

  instance.instance_variable_set(:@logger, get_logger(instance.log_file))

  raise IncompleteConfiguration.new("Missing attributes:\n #{missing_attrs.join("\n ")}") unless missing_attrs.empty?

  instance.instance_variable_set(:@configured, true)
end
defaults() click to toggle source
# File lib/flash_flow/config.rb, line 64
def self.defaults
  {
      branch_info_file: 'README.rdoc',
      log_file: 'log/flash_flow.log',
      notifier: nil,
      lock: nil,
      branches: nil
  }
end
get_logger(log_file) click to toggle source
# File lib/flash_flow/config.rb, line 51
def self.get_logger(log_file)
  if log_file.to_s.empty?
    log_file = '/dev/null'
  elsif log_file.to_s.upcase == 'STDOUT'
    log_file = STDOUT
  else
    dir = File.dirname(log_file)
    FileUtils.mkdir_p(dir)
  end
  Logger.new(log_file)

end
symbolize_keys!(hash) click to toggle source
# File lib/flash_flow/config.rb, line 74
def self.symbolize_keys!(hash)
  hash.keys.each do |k|
    unless k.is_a?(Symbol)
      hash[k.to_sym] = hash[k]
      hash.delete(k)
    end
  end
  hash
end