Sha256: bb8bae8fbaeda90dff107ad50678386ebe3cb94351a13b0dc1827db0dc34ea3b

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require 'yaml'

module VagrantPlugins
	module DrupalVmSites
		class Configure

			def self.editConfig(url, path)
				projectDirectory = File.expand_path(File.dirname(__FILE__) + '/templates/')
				sitesConfig = YAML.load_file(projectDirectory + '/config-template.yml')

				if path
					sitesConfig['vagrant_synced_folders'][0]['local_path'] = path
				else
					sitesConfig['vagrant_synced_folders'][0]['local_path'] = '~/Sites/' + url + '/www';
				end

				sitesConfig['vagrant_synced_folders'][0]['destination'] = '/var/www/' + url;
				sitesConfig['apache_vhosts'][0]['servername'] = url.split('.')[0] + '.dev';
				sitesConfig['apache_vhosts'][0]['serveralias'] = 'www.' + url.split('.')[0] + '.dev';
				sitesConfig['apache_vhosts'][0]['documentroot'] = '/var/www/' + url;
				sitesConfig['mysql_databases'][0]['name'] = url.split('.')[0];

				return sitesConfig;
			end

			def self.call
				currentDirectory = Dir.pwd
				sites = YAML.load_file(currentDirectory + '/drupal-vm-sites.yml')

				config = {};
				folders = [];
				vhosts = [];
				databases = [];

				for site in sites
					config['vagrant_synced_folders'] = editConfig(site[1]['url'], site[1]['path'])['vagrant_synced_folders']
					config['apache_vhosts'] = editConfig(site[1]['url'], site[1]['path'])['apache_vhosts']
					config['mysql_databases'] = editConfig(site[1]['url'], site[1]['path'])['mysql_databases']

					folders.push(config['vagrant_synced_folders'][0])
					vhosts.push(config['apache_vhosts'][0])
					databases.push(config['mysql_databases'][0])
				end

				config['vagrant_synced_folders'] = folders
				config['apache_vhosts'] = vhosts
				config['mysql_databases'] = databases

				File.open(currentDirectory + '/config.yml', 'w') {|f| f.write config.to_yaml }

				puts 'Configuration file generated!'
				0
			end
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
drupal-vm-sites-0.0.6 lib/drupal-vm-sites/configure.rb
drupal-vm-sites-0.0.5 lib/drupal-vm-sites/configure.rb