Module: Gitomator::Util

Defined in:
lib/gitomator.rb,
lib/gitomator/util/repo/name_resolver.rb

Defined Under Namespace

Modules: Repo

Class Method Summary collapse

Class Method Details

.create_logger(config = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitomator.rb', line 29

def self.create_logger(config = {})
  gem 'logger'; require 'logger'

  if config.nil?
    return Logger.new(STDOUT)
  end

  output = STDOUT
  case config['output']
  when nil
    output = STDOUT
  when 'STDOUT'
    output = STDOUT
  when 'STDERR'
    output = STDERR
  when 'NULL' || 'OFF'        # Write the dev/null (i.e. logging is off)
    output = File.open(File::NULL, "w")
  else
    output = File.open(config['output'], "a")
  end

  lgr = Logger.new(output)
  if config['level']
    lgr.level = Logger.const_get(config['level'])
  end
  return lgr
end

.load_config(config) ⇒ Object

Given a config file (path to file, or an object that responds to :read), do that ERB+YAML thing, and return a Hash.

Parameters:

  • config (String/File)

Returns:

  • Hash



16
17
18
19
20
21
22
23
24
25
# File 'lib/gitomator.rb', line 16

def self.load_config(config)
  require 'erb'
  require 'yaml'

  if config.respond_to? :read
    YAML::load(ERB.new(config.read).result)
  else
    YAML::load(ERB.new(File.read(config)).result)
  end
end