Created
March 28, 2016 16:14
-
-
Save dayer4b/b9b294f6d7d5f0b1e1bb to your computer and use it in GitHub Desktop.
"figaro" for sinatra
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
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 | |
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
# goes in config/application.yml | |
defaults: &defaults | |
APP_NAME: "my app" | |
development: | |
<<: *defaults | |
test: | |
<<: *defaults | |
staging: | |
<<: *defaults | |
production: | |
<<: *defaults |
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
require 'sinatra-syslog' | |
require_relative 'app' | |
require_relative 'load_secrets' | |
use Sinatra::Syslog, "[sinatra] [#{ENV['APP_NAME']}-#{ENV['RACK_ENV']}] " | |
run Application |
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
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