class Bricolage::ConfigLoader

Public Class Methods

new(app_home) click to toggle source
# File lib/bricolage/configloader.rb, line 13
def initialize(app_home)
  @app_home = app_home
  @base_dir = Pathname('.')
end

Public Instance Methods

eruby(text, path) click to toggle source
# File lib/bricolage/configloader.rb, line 34
def eruby(text, path)
  erb = ERB.new(text, nil, '%-')
  erb.filename = path.to_s
  push_base_dir(path) {
    erb.result(binding())
  }
end
load_eruby(path) click to toggle source
# File lib/bricolage/configloader.rb, line 22
def load_eruby(path)
  eruby(load_file(path), path)
end
Also aliased as: load_text
load_file(path) click to toggle source
# File lib/bricolage/configloader.rb, line 28
def load_file(path)
  File.read(path)
rescue SystemCallError => err
  raise ParameterError, "could not read file: #{err.message}"
end
load_text(path)
Alias for: load_eruby
load_yaml(path) click to toggle source
# File lib/bricolage/configloader.rb, line 18
def load_yaml(path)
  parse_yaml(load_eruby(path), path)
end

Private Instance Methods

app_home() click to toggle source
# File lib/bricolage/configloader.rb, line 56
def app_home
  @app_home or raise ParameterError, "app_home is not given in this file"
end
base_dir() click to toggle source
# File lib/bricolage/configloader.rb, line 60
def base_dir
  @base_dir
end
parse_yaml(text, path) click to toggle source
# File lib/bricolage/configloader.rb, line 44
def parse_yaml(text, path)
  YAML.load(text)
rescue => err
  raise ParameterError, "#{path}: config file syntax error: #{err.message}"
end
push_base_dir(path) { || ... } click to toggle source
# File lib/bricolage/configloader.rb, line 64
def push_base_dir(path)
  saved, @base_dir = @base_dir, Pathname(path).parent
  begin
    yield
  ensure
    @base_dir = saved
  end
end
read_config_file(path) click to toggle source

$base_dir + “vars.yml” -> “$base_dir/vars.yml” $base_dir + “/abs/path/vars.yml” -> “/abs/path/vars.yml”

# File lib/bricolage/configloader.rb, line 75
def read_config_file(path)
  load_eruby(relative_path(Pathname(path)))
end