Method: #overwrite_config
- Defined in:
- lib/easel.rb
#overwrite_config(yaml_filename) ⇒ Object
overwrite_config
Overwrites the $config fields that are set in the YAML file provided on input. TODO: Log (error?) every key in the YAML file that does not exist in $config.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/easel.rb', line 97 def overwrite_config yaml_filename # TODO: Rewrite using pattern matching to allow checking if the # yaml_contents.each is one of the base keys. If so, check that the associated # value matches the expected nesting. Do that 'no other values' check. # TODO: Ensure that the command names are less than 1020 bytes (because I'm # setting the max length of a single websocket message to 1024 (minus 'STOP:')) begin yaml_contents = YAML.load_file $config[:yaml_file] rescue Exception => e log_fatal "YAML failed to load. Error Message: #{e}" end def loop_overwrite (config, yaml) yaml.each_key { |key| if yaml[key].is_a? Hash loop_overwrite(config[key.to_sym], yaml[key]) elsif yaml[key].is_a? Array config[key.to_sym] = [] yaml[key].each { |elmnt| element = {} loop_overwrite(element, elmnt) config[key.to_sym] << element } else config[key.to_sym] = yaml[key] end } end loop_overwrite($config, yaml_contents) end |