Class: SingularityClient::ConfigLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/singularity_client/config_loader.rb

Overview

Wrapper around the config object

Constant Summary collapse

DOTFILE =
'.singularity.yml'

Class Method Summary collapse

Class Method Details

.find_config_file(dir, debug) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/singularity_client/config_loader.rb', line 19

def self.find_config_file(dir, debug)
  Pathname.new(File.expand_path(dir)).ascend do |path|
    file = File.join(path.to_s, DOTFILE)
    if File.exist?(file)
      puts "DEBUG: Using configuration from #{file}" if debug
      return file
    end
  end

  puts 'DEBUG: Could not find .singularity.yml' if debug
end

.load_from_file(file = false, debug = false) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/singularity_client/config_loader.rb', line 11

def self.load_from_file(file = false, debug = false)
  # If file is defined don't look for one, else find one
  file = find_config_file('.', debug) unless file

  # If no config file passed in, and none found, return empty hash
  file ? YAML.load_file(file) : {}
end