Method: Origen::SiteConfig::Config#load
- Defined in:
- lib/origen/site_config/config.rb
#load ⇒ Object
Loads the site config into memory. Process the site config as an ERB, if indicated to do so (.erb file extension) After the initial load, any centralized site configs will be retreived (if needed), cached, and loaded.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/origen/site_config/config.rb', line 122 def load def read_erb(erb) ERB.new(File.read(erb), 0, '%<>') end # YAML.safe_load is prefered # rubocop:disable Security/YAMLLoad if centralized? if !cached? if fetch erb = read_erb(cached_file) else # There was a problem fetching the config. Just use an empty string. # Warning message will come from #fetch erb = ERB.new('') end else erb = read_erb(cached_file) end @values = (YAML.load(erb.result) || {}) else if File.extname(path) == '.erb' erb = read_erb(path) @values = (YAML.load(erb.result) || {}) else @values = (YAML.load_file(path) || {}) end end # rubocop:enable Security/YAMLLoad unless @values.is_a?(Hash) puts red("Origen: Site Config: The config at #{path} was not parsed as a Hash, but as a #{@values.class}") puts red(' Please review the format of the this file.') puts red(' Alternatively, an error condition may have been received from the server.') puts red(" This site config is available at: #{cached_file}") puts red(' This config will not be loaded and will be replaced with an empty config.') puts @values = {} end if centralized? # check for restricted centralized config values RESTRICTED_FROM_CENTRALIZED_VARIABLES.each do |var| if @values.key?(var) val = @values.delete(var) puts red("Origen: Site Config: config variable #{var} is not allowed in the centralized site config and will be removed.") puts red(" Value #{val} will not be applied!") end end end @loaded = true @values end |