class Reviser::Cfg
Externalises the configuration Cfg
acts like a hash whose entries are config keys associated with their values
@author Renan Strauss
Constants
- OUT_FORMATS
The available out formats
- RES_DIR
Resources dir
- ROOT
Path for specialized config files for projects
- TYPE_DIR
Project’s type dir
Public Class Methods
[](key)
click to toggle source
# File lib/reviser/config.rb, line 52 def self.[](key) @@mem[key] if @@loaded end
[]=(key, value)
click to toggle source
# File lib/reviser/config.rb, line 56 def self.[]=(key, value) @@mem[key] = value if @@loaded end
has_key?(key)
click to toggle source
@return true if there is the key in the config
# File lib/reviser/config.rb, line 61 def self.has_key?(key) @@mem.has_key? key end
load(cfg_file)
click to toggle source
# File lib/reviser/config.rb, line 87 def self.load(cfg_file) @@mem = {} @@workspace_root = File.expand_path(File.dirname(cfg_file)) # # read our main config file # populate YAML.load(File.read(cfg_file)) # # look for project's type type_file = File.join(@@workspace_root, TYPE_DIR, "#{@@mem[:type]}.yml") begin type_cfg = YAML.load(File.read(type_file)) rescue => e puts "File #{type_file} not found. Aborting..." exit end populate YAML.load(File.read(File.join(ROOT, 'lang', "#{type_cfg['language']}.yml"))) # So that project's type Cfg overrides # lang Cfg populate type_cfg setup_defaults @@loaded = true end
resource(path)
click to toggle source
@return The specified resource path TODO : put resources in dedicated folders for each component or extension, so that the user can omit <lang>/<ext_name>/ when calling this method
# File lib/reviser/config.rb, line 82 def self.resource path self.workspace_file File.join(RES_DIR, path) end
setup_defaults()
click to toggle source
# File lib/reviser/config.rb, line 116 def self.setup_defaults # # Default values for optional keys # @@mem[:options] ||= { verbose: true, log_dir:'logs', log_mode: 'org' } @@mem[:timeout] ||= 4 @@mem[:out] ||= 'results' @@mem[:out_format] ||= ['csv', 'html'] @@mem[:required_files] ||= [] @@mem[:program_prefix] ||= '' @@mem[:execution_command] ||= '' @@mem[:execution_count] ||= 1 @@mem[:create_git_repo] ||= false end
workspace_file(f)
click to toggle source
@return The specified
# File lib/reviser/config.rb, line 68 def self.workspace_file f path = File.join @@workspace_root, f raise Errno::ENOENT, "#{path}".magenta unless File.exists?(path) File.new(path) end
Private Class Methods
populate(hash)
click to toggle source
Handy method to convert string keys read from Cfg
file to symbols
# File lib/reviser/config.rb, line 138 def self.populate(hash) hash.each { |k, v| @@mem[k.to_sym] = v} end