Skip to content

Commit

Permalink
abstract settings for heroku, can use travis-cli for configuring and …
Browse files Browse the repository at this point in the history
…deploying to heroku now
  • Loading branch information
Sven Fuchs committed Jan 4, 2012
1 parent 692be63 commit db54363
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,6 +1,6 @@
.bundle
config/database.yml
config/settings.yml
config/travis.yml
db/*.sqlite3
log/*.log
tmp/
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -4,4 +4,4 @@

require File.expand_path('../config/application', __FILE__)

Saas::Application.load_tasks
Travis::Application.load_tasks
2 changes: 1 addition & 1 deletion config/application.rb
Expand Up @@ -9,7 +9,7 @@
# Bundler.require(:default, :assets, Rails.env)
end

module Saas
module Travis
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down
2 changes: 1 addition & 1 deletion config/environment.rb
Expand Up @@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Saas::Application.initialize!
Travis::Application.initialize!
2 changes: 1 addition & 1 deletion config/environments/development.rb
@@ -1,4 +1,4 @@
Saas::Application.configure do
Travis::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# In the development environment your application's code is reloaded on
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
@@ -1,4 +1,4 @@
Saas::Application.configure do
Travis::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# Code is not reloaded between requests
Expand Down
2 changes: 1 addition & 1 deletion config/environments/test.rb
@@ -1,4 +1,4 @@
Saas::Application.configure do
Travis::Application.configure do
# Settings specified here will take precedence over those in config/application.rb

# The test environment is used exclusively to run your application's
Expand Down
14 changes: 0 additions & 14 deletions config/initializers/assets.rb

This file was deleted.

3 changes: 3 additions & 0 deletions config/initializers/config.rb
@@ -0,0 +1,3 @@
require 'settings'

Rails.application.config.settings = Settings.new.load('config/settings.yml', Rails.env)
6 changes: 3 additions & 3 deletions config/initializers/devise.rb
@@ -1,10 +1,10 @@
settings = Hashr.new(YAML.load(File.read('config/settings.yml')))
settings = Rails.application.config.settings

Devise.setup do |c|
require 'devise/orm/active_record'

c.http_authenticatable = true

c.omniauth :github, settings.github.client_id, settings.github.client_secret, :scope => settings.github.scope
c.omniauth :twitter, settings.twitter.client_id, settings.twitter.client_secret
# c.omniauth :github, settings.github.client_id, settings.github.client_secret, :scope => settings.github.scope
# c.omniauth :twitter, settings.twitter.client_id, settings.twitter.client_secret
end
2 changes: 1 addition & 1 deletion config/initializers/secret_token.rb
Expand Up @@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Saas::Application.config.secret_token = '6e2b941713e5b9fa57cdff558772b88dc6dca42e74641bb01b835b0caa70526a0baf3c264a5bb6815cf1f5943ed48499ec66939e8984e0d84beed97b01923c0c'
Travis::Application.config.secret_token = '6e2b941713e5b9fa57cdff558772b88dc6dca42e74641bb01b835b0caa70526a0baf3c264a5bb6815cf1f5943ed48499ec66939e8984e0d84beed97b01923c0c'
2 changes: 1 addition & 1 deletion config/initializers/session_store.rb
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.

Saas::Application.config.session_store :cookie_store, key: '_saas_session'
Travis::Application.config.session_store :cookie_store, key: '_travis_session'

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/stripe.rb
@@ -1,4 +1,4 @@
settings = Hashr.new(YAML.load(File.read('config/settings.yml')))
settings = Rails.application.config.settings

Stripe.api_key = settings.stripe.secret_key
STRIPE_PUBLIC_KEY = settings.stripe.public_key
2 changes: 1 addition & 1 deletion config/routes.rb
@@ -1,4 +1,4 @@
Saas::Application.routes.draw do
Travis::Application.routes.draw do
root to: 'home#show'

match 'packages/:package', as: :new_package, to: 'orders#new'
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions lib/settings.rb
@@ -0,0 +1,32 @@
require 'hashr'
require 'yaml'

class Settings < Hashr
extend Hashr::EnvDefaults

self.env_namespace = 'travis'

define :stripe => { secret_key: '', public_key: '' }

def load(filename, env = nil)
settings = File.exists?(filename) ? YAML.load(File.read(filename)) : {}
settings = settings[env.to_s] || {} if env
settings.each { |key, value| self[key] = value }
self
end

def export_env!
export_env.each { |key, value| ENV[key] = value }
end

def export_env
collector = lambda do |hash, stack|
hash.map do |key, value|
stack.push(key.to_s.upcase)
result = value.is_a?(Hash) ? collector.call(value, stack) : [stack.join('_'), value]
result.tap { stack.pop }
end
end
Hash[*collector.call(self, [self.class.env_namespace].compact).flatten]
end
end

0 comments on commit db54363

Please sign in to comment.