Skip to content

Instantly share code, notes, and snippets.

@wflanagan
Created October 15, 2018 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wflanagan/e134f10f9db33aa3883262a604f219f8 to your computer and use it in GitHub Desktop.
Save wflanagan/e134f10f9db33aa3883262a604f219f8 to your computer and use it in GitHub Desktop.
# 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
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:
is: "Your config file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment