improved configuration utility

This commit is contained in:
Hauke Klement
2015-02-05 09:52:17 +01:00
parent f9d26b1a6f
commit 37a632d2a1
6 changed files with 62 additions and 9 deletions

View File

@ -4,11 +4,17 @@ module CodeOcean
@filename = filename
end
def read
path = Rails.root.join('config', "#{@filename}.yml")
if File.exists?(path)
YAML.load_file(path)[Rails.env].symbolize_keys
def read(options = {})
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
if ::File.exists?(path)
content = options[:erb] ? YAML.load(ERB.new(::File.new(path, 'r').read).result) : YAML.load_file(path)
content[Rails.env].with_indifferent_access
else
raise Error.new("Configuration file not found: #{path}")
end
end
end
class Config::Error < RuntimeError
end
end

View File

@ -1,5 +1,4 @@
class DockerClient
CONFIG_PATH = Rails.root.join('config', 'docker.yml.erb')
CONTAINER_WORKSPACE_PATH = '/workspace'
LOCAL_WORKSPACE_ROOT = Rails.root.join('tmp', 'files', Rails.env)
@ -29,7 +28,7 @@ class DockerClient
private :command_substitutions
def self.config
YAML.load(ERB.new(File.new(CONFIG_PATH, 'r').read).result)[Rails.env].with_indifferent_access
@config ||= CodeOcean::Config.new(:docker).read(erb: true)
end
def copy_file_to_workspace(options = {})