Skip to content

Instantly share code, notes, and snippets.

/config.rb Secret

Created December 30, 2012 06:33
Show Gist options
  • Save anonymous/86ba439c211f4f554989 to your computer and use it in GitHub Desktop.
Save anonymous/86ba439c211f4f554989 to your computer and use it in GitHub Desktop.
require 'singleton'
#require 'awesome_print'
module DeployMaster
end
class DeployMaster::Config
include Singleton
CONFIG_LOCATION = 'deploy.yml'
def self.config_location
CONFIG_LOCATION
end
attr_reader :config
def initialize
@config = load_config_yaml
# Run lots of functions to edit the config
end
def load_config_yaml
raise "You do not have a deploy.yml configuration file at #{config_location}" if !File.exists?(DeployMaster::Config.config_location)
YAML.load(File.open(DeployMaster::Config.config_location))
end
end
class DeployMaster::Nginx
def initialize(server_name)
setup_this_servers_config_only(server_name)
end
def load_config
DeployMaster::Config.instance.config
end
def setup_this_servers_config_only(server_name)
@server_name = server_name
@config = load_config
# remove all the apps that do not have any stages set up on this server
@config['apps'].reject! {|app_name, app_config| !app_config.search('stages/*/server').values.include?(server_name) }
# Remove all stages that are not setup on that server
@config.search('apps/*/stages/*').reject! {|element| element[:value]['server'] != server_name}
end
end
base = File.expand_path(File.dirname(__FILE__) + '/../..')
require "#{base}/spec/spec_helper"
require "#{base}/lib/deploy_master/01_config"
require "#{base}/lib/deploy_master/11_nginx"
describe 'nginx' do
describe 'generate_url_redirections_text_for' do
it 'should return the url redirections for all apps and stages' do
# Change the yaml file which is loaded
DeployMaster::Config.stub(:config_location).and_return(File.dirname(__FILE__) + '/../test_config_yamls/06_test_deploy_for_url_config.yaml')
apps_config = DeployMaster::Nginx.new('production').config['apps']
result = nginx.generate_url_redirections_text_for(apps_config)
expected_result = 0
result.should == expected_result
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment