Skip to content

Instantly share code, notes, and snippets.

@DanKnox
Last active December 11, 2015 21:09
Show Gist options
  • Save DanKnox/4660077 to your computer and use it in GitHub Desktop.
Save DanKnox/4660077 to your computer and use it in GitHub Desktop.
require "ostruct"
module HL7ClientInterface
class Config::FileMissing < Errno::ENOENT; end
def self.config
@config ||= load_configuration
end
def self.document_types
@document_types ||= config['document_types']
end
def self.load_configuration
config = YAML::load_file("config.yml") || raise(Config::FileMissing, "Add settings to config.yml")
settings = config[(ENV["RACK_ENV"] || "development")]
OpenStruct.new(settings)
rescue Errno::ENOENT
raise Config::FileMissing, "config.yml missing"
end
end
# Now access the config elsewhere using the .config method
HL7ClientFileInterface.config.db_name
HL7ClientFileInterface.config.db_username
# and so forth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment