mardi 15 mars 2016

Custom configuration file in Rails 3. How does this work?

I am taking a look at a legacy code base and I found this inside app/lib/app_configs.rb:

class AppConfigs   CONFIG_ROOT = File.join(Rails.root, 'config', 'app_configs')

  def self.[](file)
    path = File.join(CONFIG_ROOT, "#{file}.yml")
    config = YAML.load(ERB.new(File.new(path).read).result)
    raise NotImplementedError if !config
    HashWithIndifferentAccess.new config[Rails.env]   

end 
end

So,

  1. app/lib is in the Ruby load path right?

  2. what does self. do?

  3. What does this method do? What does YAML.load and ERB.new do?

  4. I found code that looks like this:

     AppConfigs[:fog][:fog_directory]
    
    

What is that?

I do have a config/app_configs/fog.yml file that looks like this:

...
test:
  fog_credentials:
    <<: *default_fog_credentials
    scheme: 'http'
    host: 'localhost'
    port: 5000
  fog_directory: '/[path to uploads]'
  asset_host: "//[something on cloudfront"
...

Aucun commentaire:

Enregistrer un commentaire