class VagrantPlugins::DrupalVmSites::Configure

Public Class Methods

call() click to toggle source
# File lib/drupal-vm-sites/configure.rb, line 26
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
editConfig(url, path) click to toggle source
# File lib/drupal-vm-sites/configure.rb, line 7
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] + '.fire';
        sitesConfig['apache_vhosts'][0]['serveralias'] = 'www.' + url.split('.')[0] + '.fire';
        sitesConfig['apache_vhosts'][0]['documentroot'] = '/var/www/' + url;
        sitesConfig['mysql_databases'][0]['name'] = url.split('.')[0];

        return sitesConfig;
end