Class: Reviser::Cfg

Inherits:
Object
  • Object
show all
Defined in:
lib/reviser/config.rb

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

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.

Returns:

  • (Boolean)

    true if there is the key in the config



61
62
63
# File 'lib/reviser/config.rb', line 61

def self.has_key?(key)
  @@mem.has_key? key
end

.load(cfg_file) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/reviser/config.rb', line 78

def self.load(cfg_file)
  @@mem = {}
  @@workspace_root = 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 // when calling this method

Returns:

  • The specified resource path



72
73
74
75
# File 'lib/reviser/config.rb', line 72

def self.resource path
  abs = File.join @@workspace_root, RES_DIR, path
  File.new abs if File.exists? abs
end

.setup_defaultsObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/reviser/config.rb', line 107

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] ||= ['html', 'csv', 'xls']
  Cfg[:required_files] ||= []

  Cfg[:program_prefix] ||= ''
  Cfg[:execution_command] ||= ''
  Cfg[:execution_count] ||= 1

  Cfg[:create_git_repo] ||= false
end