Skip to content

Instantly share code, notes, and snippets.

@dayer4b
Created March 28, 2016 16:14
Show Gist options
  • Save dayer4b/b9b294f6d7d5f0b1e1bb to your computer and use it in GitHub Desktop.
Save dayer4b/b9b294f6d7d5f0b1e1bb to your computer and use it in GitHub Desktop.
"figaro" for sinatra
require_relative 'load_secrets'
require 'sinatra/base'
class Application < Sinatra::Base
configure do
enable :logging, :show_exceptions, :dump_errors, :clean_trace, :static
end
enable :inline_templates
get '/' do
"Hello World"
end
end
# goes in config/application.yml
defaults: &defaults
APP_NAME: "my app"
development:
<<: *defaults
test:
<<: *defaults
staging:
<<: *defaults
production:
<<: *defaults
require 'sinatra-syslog'
require_relative 'app'
require_relative 'load_secrets'
use Sinatra::Syslog, "[sinatra] [#{ENV['APP_NAME']}-#{ENV['RACK_ENV']}] "
run Application
require 'yaml'
require 'erb'
path = 'config/application.yml'
environment = ENV['RACK_ENV']
parsed_yaml = YAML.load(ERB.new(File.read(path)).result)
envs = parsed_yaml[environment]
envs.each do |key, value|
ENV[key] = value unless ENV.key?(key)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment