Last active
January 31, 2022 11:48
-
-
Save valarpirai/e7dc78809533270cd869a99657bc2c54 to your computer and use it in GitHub Desktop.
Load configs from ERB based YML files in Rails application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AppConfig | |
def self._config | |
@_config ||= ErbYaml.load_file("#{Rails.root}/config/app_configuration.yml") | |
end | |
def self.env | |
_config["env_name"] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defaults: &defaults | |
env_name: "<%= Rails.env %>" | |
development: &development | |
<<: *defaults | |
qa: | |
<<: *defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ErbYaml | |
def self.load_file(path, a_binding = binding) | |
content = File.read(path) | |
YAML.load(ERB.new(content).result(a_binding))[Rails.env] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment