Module: BBFS::Params

Defined in:
lib/params.rb,
lib/params/version.rb

Defined Under Namespace

Classes: Param

Constant Summary collapse

VERSION =

Parser updated in params.rb

"0.0.9"

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Read global param value by other modules. Note that this operator should only be used, after parameter has been defined through one of Param module methods: Params.string, Params.integer, Params.float or Params.boolean.“



157
158
159
160
# File 'lib/params.rb', line 157

def Params.[](name)
  raise_error_if_param_does_not_exist(name)
  @globals_db[name].value
end

.[]=(name, value) ⇒ Object

Write global param value by other modules. Note that this operator should only be used, after parameter has been defined through one of Param module methods: Params.string, Params.integer, Params.float or Params.boolean.“



166
167
168
169
170
# File 'lib/params.rb', line 166

def Params.[]=(name, value)
  raise_error_if_param_does_not_exist(name)
  set_value = @globals_db[name].value_type_check(value)
  @globals_db[name].value = set_value
end

.boolean(name, value, description) ⇒ Object

Define new global parameter of type Boolean.



209
210
211
212
# File 'lib/params.rb', line 209

def Params.boolean(name, value, description)
  raise_error_if_param_exists(name)
  @globals_db[name] = Param.new(name, value, 'Boolean', description)
end

.float(name, value, description) ⇒ Object

Define new global parameter of type Float.



197
198
199
200
# File 'lib/params.rb', line 197

def Params.float(name, value, description)
  raise_error_if_param_exists(name)
  @globals_db[name] = Param.new(name, value, 'Float', description)
end

.get_init_messagesObject



63
64
65
# File 'lib/params.rb', line 63

def Params.get_init_messages
  return @init_debug_messages
end

.init(args) ⇒ Object

Initializes the project parameters. Precedence is: Defined params, file and command line is highest.



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/params.rb', line 216

def Params.init(args)
  @init_debug_messages = []
  results = parse_command_line_arguments(args)
  if not results['conf_file'].nil?
    Params['conf_file'] = File.expand_path(results['conf_file'])
  end

  #load yml params if path is provided and exists
  if Params['conf_file'].nil?
    @init_debug_messages << 'Configuration file was not provided.' + \
                            'Skipping loading file parameters.'
  else
    if File.exist?(Params['conf_file'])
      @init_debug_messages << "Loading parameters from configuration file:'#{Params['conf_file']}'"
      read_yml_params(File.open(Params['conf_file'], 'r'))
    else
      @init_debug_messages << "Configuration file path:'#{Params['conf_file']}' does not exist. " + \
                            "Skipping loading file parameters."
    end
  end

  #override command line argument
  results.keys.each do |result_name|
    override_param(result_name, results[result_name])
  end

  print_global_parameters

  # Prints help and parameters if needed.
  puts @help_messages unless @help_messages.empty?
  puts @init_debug_messages if Params['print_params_to_stdout']
  exit unless @help_messages.empty?
end

.integer(name, value, description) ⇒ Object

Define new global parameter of type Integer.



191
192
193
194
# File 'lib/params.rb', line 191

def Params.integer(name, value, description)
raise_error_if_param_exists(name)
@globals_db[name] = Param.new(name, value, 'Integer', description)
end

.string(name, value, description) ⇒ Object

Define new global parameter of type String.



203
204
205
206
# File 'lib/params.rb', line 203

def Params.string(name, value, description)
  raise_error_if_param_exists(name)
  @globals_db[name] = Param.new(name, value, 'String', description)
end