module Jello
class Config
class << self
private
def create_methods(items)
items.each do |item|
define_singleton_method item.downcase do
@@config[item]
end
end
end
def get_config
@@config ||= YAML.load(File.read "config/development.yaml")
end
end
create_methods get_config.keys
end
end
# Just verify that things that shouldn't be accessible, definitely aren't accessible
Jello::Config.get_config
# NoMethodError: private method `get_config' called for Jello::Config:Class
Jello::Config.config
# NoMethodError: undefined method `config' for Jello::Config:Class
Jello::Config.DEV_KEY
# NoMethodError: undefined method `DEV_KEY' for Jello::Config:Class
Jello::Config.dev_key
# "12345a6b78d90e1f2gh345ijk6l78m90" (not real dev key obviously)