Permalink
Browse files

cleaned up some repeated code

  • Loading branch information...
1 parent 29caa9b commit 3b03dc19beb9b436aff13967bef1f12e8e9fca75 @rauhryan rauhryan committed Jul 3, 2012
Showing with 30 additions and 38 deletions.
  1. +2 −0 .settings.sample
  2. +1 −19 lib/api.rb
  3. +1 −19 lib/app.rb
  4. +26 −0 lib/helpers.rb
View
@@ -1,3 +1,5 @@
+
+# TODO: read this from a yaml
set :secret_key, 'iam a secret key'
set :team_id, "1235125"
set :github_options, {
View
@@ -5,25 +5,7 @@ class API < Sinatra::Base
register Sinatra::Auth::Github
register Huboard::Common
- puts "settings.root #{settings.root}"
- if File.exists? "#{File.dirname(__FILE__)}/../.settings"
- puts "settings file"
- token_file = File.new("#{File.dirname(__FILE__)}/../.settings")
- eval(token_file.read)
- end
-
- if ENV['GITHUB_CLIENT_ID']
- set :secret_key, ENV['SECRET_KEY']
- set :team_id, ENV["TEAM_ID"]
- set :user_name, ENV["USER_NAME"]
- set :password, ENV["PASSWORD"]
- set :github_options, {
- :secret => ENV['GITHUB_SECRET'],
- :client_id => ENV['GITHUB_CLIENT_ID'],
- :scopes => "user,repo"
- }
- set :session_secret, ENV["SESSION_SECRET"]
- end
+ extend Huboard::Common::Settings
before do
authenticate! unless authenticated?
View
@@ -11,25 +11,7 @@ class App < Sinatra::Base
register Sinatra::Auth::Github
register Huboard::Common
- puts "settings.root #{settings.root}"
- if File.exists? "#{File.dirname(__FILE__)}/../.settings"
- puts "settings file"
- token_file = File.new("#{File.dirname(__FILE__)}/../.settings")
- eval(token_file.read)
- end
-
- if ENV['GITHUB_CLIENT_ID']
- set :secret_key, ENV['SECRET_KEY']
- set :team_id, ENV["TEAM_ID"]
- set :user_name, ENV["USER_NAME"]
- set :password, ENV["PASSWORD"]
- set :github_options, {
- :secret => ENV['GITHUB_SECRET'],
- :client_id => ENV['GITHUB_CLIENT_ID'],
- :scopes => "user,repo"
- }
- set :session_secret, ENV["SESSION_SECRET"]
- end
+ extend Huboard::Common::Settings
PUBLIC_URLS = ['/', '/logout']
before do
View
@@ -1,6 +1,32 @@
require 'ghee'
module Huboard
module Common
+ module Settings
+
+ def self.extended(klass)
+ klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ if File.exists? "#{File.dirname(__FILE__)}/../.settings"
+ puts "settings file"
+ token_file = File.new("#{File.dirname(__FILE__)}/../.settings")
+ # TODO: read this from a yaml
+ eval(token_file.read)
+ elsif ENV['GITHUB_CLIENT_ID']
+ set :secret_key, ENV['SECRET_KEY']
+ set :team_id, ENV["TEAM_ID"]
+ set :user_name, ENV["USER_NAME"]
+ set :password, ENV["PASSWORD"]
+ set :github_options, {
+ :secret => ENV['GITHUB_SECRET'],
+ :client_id => ENV['GITHUB_CLIENT_ID'],
+ :scopes => "user,repo"
+ }
+ set :session_secret, ENV["SESSION_SECRET"]
+ else
+ raise "Configuration information not found: you need to provide a .settings file or ENV variables"
+ end
+ RUBY
+ end
+ end
module Helpers
def encrypted_token

0 comments on commit 3b03dc1

Please sign in to comment.