Class: Reviser::Cfg
- Inherits:
-
Object
- Object
- Reviser::Cfg
- Defined in:
- lib/reviser/config.rb
Overview
Externalises the configuration Cfg acts like a hash whose entries are config keys associated with their values
Constant Summary collapse
- ROOT =
Path for specialized config files for projects
File.join(File.dirname(File.dirname(File.dirname(__FILE__))))
- RES_DIR =
Resources dir
'res'
- TYPE_DIR =
Project's type dir
'type'
- OUT_FORMATS =
The available out formats
[:csv, :html, :xls]
- @@loaded =
Is the config is loaded ?
false
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
-
.has_key?(key) ⇒ Boolean
True if there is the key in the config.
- .load(cfg_file) ⇒ Object
-
.resource(path) ⇒ Object
TODO : put resources in dedicated folders for each component or extension, so that the user can omit
/ / when calling this method. - .setup_defaults ⇒ Object
-
.workspace_file(f) ⇒ Object
The specified.
Class Method Details
.[](key) ⇒ Object
52 53 54 |
# File 'lib/reviser/config.rb', line 52 def self.[](key) @@mem[key] if @@loaded end |
.[]=(key, value) ⇒ Object
56 57 58 |
# File 'lib/reviser/config.rb', line 56 def self.[]=(key, value) @@mem[key] = value if @@loaded end |
.has_key?(key) ⇒ Boolean
Returns true if there is the key in the config.
61 62 63 64 |
# File 'lib/reviser/config.rb', line 61 def self.has_key?(key) @@mem.has_key? key end |
.load(cfg_file) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/reviser/config.rb', line 87 def self.load(cfg_file) @@mem = {} @@workspace_root = File.(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) ⇒ Object
TODO : put resources in dedicated folders
for each component or extension, so that
the user can omit
82 83 84 |
# File 'lib/reviser/config.rb', line 82 def self.resource path self.workspace_file File.join(RES_DIR, path) end |
.setup_defaults ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/reviser/config.rb', line 116 def self.setup_defaults # # Default values for optional keys # Cfg[:options] ||= { verbose: true, log_dir:'logs', log_mode: 'org' } Cfg[:timeout] ||= 4 Cfg[:out] ||= 'results' Cfg[:out_format] ||= ['csv', 'html'] Cfg[:required_files] ||= [] Cfg[:program_prefix] ||= '' Cfg[:execution_command] ||= '' Cfg[:execution_count] ||= 1 Cfg[:create_git_repo] ||= false end |
.workspace_file(f) ⇒ Object
Returns The specified.
68 69 70 71 72 73 |
# 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 |