Created
October 15, 2018 11:47
-
-
Save wflanagan/e134f10f9db33aa3883262a604f219f8 to your computer and use it in GitHub Desktop.
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
# How to use | |
YourService::Config.config is always your config | |
YourService::Config.config['hello'] = true # writes your config data | |
YourService::Config.save! # persists do disk | |
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 YourService | |
class Config | |
class << self | |
def config | |
@config ||= new.config | |
end | |
end | |
def config | |
@config ||= YAML.load(File.read(config_file)) | |
end | |
def config_file | |
@config_file ||= begin | |
File.expand_path( | |
File.join( | |
File.dirname(__FILE__, 'config.yml') | |
) | |
) | |
end | |
end | |
def save! | |
File.open(config_file, 'w') {|f| f.write config.to_yaml } | |
end | |
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
--- | |
this: | |
is: "Your config file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment