Module: InputLoader
- Defined in:
- lib/teuton-client/input_loader.rb
Overview
Methods that read config params
Class Method Summary collapse
-
.read_configuration(input) ⇒ String, Integer
Read input arguments and return config params.
-
.read_yaml(filepath) ⇒ Hash
Read YAML configuration file.
Class Method Details
.read_configuration(input) ⇒ String, Integer
Read input arguments and return config params. Arguments:
-
YAML file => Read file.yaml as config file
-
Empty
* Exist default config file => Read config file * Dosn't exist config file => Set defaults IP, PORT values
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/teuton-client/input_loader.rb', line 16 def self.read_configuration(input) if input.size.zero? && File.exists?(Application::CONFIGFILE) param = read_yaml(Application::CONFIGFILE) return param[:server][:ip], param[:server][:port] end unless input.size == 2 puts "Usage: teuton-client help" exit 1 end ip = input[0] port = (input[1].to_i > 16000 ? input[1] : (input[1].to_i + 16000).to_s) return ip, port end |
.read_yaml(filepath) ⇒ Hash
Read YAML configuration file.
35 36 37 38 39 40 41 42 |
# File 'lib/teuton-client/input_loader.rb', line 35 def self.read_yaml(filepath) unless File.exists? filepath puts "teuton-client => " + Rainbow("[ERROR] Config file \'#{filepath}\' not found!").red exit 1 end return YAML.load_file(filepath) end |