Skip to content
Snippets Groups Projects
Commit 43090d38 authored by Maxwell Salzberg's avatar Maxwell Salzberg
Browse files

AppConfig in heroku can now read array variables

parent a7d59ce1
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,14 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'uri'
require File.join(Rails.root, 'lib', 'enviroment_configuration')
class AppConfig < Settingslogic
ARRAY_VARS = [:community_spotlight, :admins]
def self.source_file_name
config_file = File.join(Rails.root, "config", "application.yml")
if !File.exists?(config_file) && (Rails.env == 'test' || Rails.env.include?("integration") || ENV["HEROKU"])
if !File.exists?(config_file) && (Rails.env == 'test' || Rails.env.include?("integration") || EnviromentConfiguration.heroku?)
config_file = File.join(Rails.root, "config", "application.yml.example")
end
config_file
......@@ -117,10 +119,18 @@ HELP
def self.[] (key)
return self.pod_uri if key == :pod_uri
return ENV[key.to_s] if ENV[key.to_s] && ENV["HEROKU"]
return fetch_from_env(key.to_s) if EnviromentConfiguration.heroku?
super
end
def fetch_from_env(key)
if ARRAY_VARS.include?(key.to_sym)
ENV[key].split(EnviromentConfiguration::ARRAY_SEPERATOR)
else
ENV[key] if ENV[key]
end
end
def self.[]= (key, value)
super
if key.to_sym == :pod_url
......
module EnviromentConfiguration
ARRAY_SEPERATOR = '%|%'
def self.heroku?
ENV['HEROKU']
end
......@@ -35,4 +36,4 @@ module EnviromentConfiguration
AppConfig[:ca_file]
end
end
end
\ No newline at end of file
end
# Copyright (c) 2012, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
require File.join(Rails.root, 'lib', 'enviroment_configuration')
namespace :heroku do
HEROKU_CONFIG_ADD_COMMAND = "heroku config:add HEROKU=true"
......@@ -6,7 +12,11 @@ namespace :heroku do
application_config = YAML.load_file('config/application.yml')['production'] rescue {}
application_config.delete_if { |k, v| v.blank? }
heroku_env = application_config.map{|k, v| "#{k}=#{v}"}.join(' ')
heroku_env = application_config.map do|key, value|
value =value.join(EnviromentConfiguration::ARRAY_SEPERATOR) if value.respond_to?(:join)
"#{key}=#{value}"
end.join(' ')
puts "Generating and setting a new secret token"
token = ActiveSupport::SecureRandom.hex(40)#reloads secret token every time you reload vars.... this expires cookies, and kinda sucks
......
......@@ -141,6 +141,28 @@ describe AppConfig do
end
end
context 'configurations which are arrays' do
it 'should be set to be admins or community_spotlight' do
AppConfig::ARRAY_VARS.should =~ [:community_spotlight, :admins]
end
context 'on heroku' do
before do
ENV['admins'] = "maxwell#{EnviromentConfiguration::ARRAY_SEPERATOR}daniel"
EnviromentConfiguration.stub(:heroku?).and_return(true)
end
after do
EnviromentConfiguration.stub(:heroku?).and_return(false)
end
it 'converts a string with ARRAY_SEPERATOR to an array' do
AppConfig[:admins].should be_a Array
end
end
end
describe ".pod_uri" do
it "properly parses the pod_url" do
AppConfig.pod_uri = nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment