Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 200978f

Browse files
committed
Fix rubocop warnings and add some exceptions.
ConditionalAssignment: No way IndentArray: No way AlignParameters: No way
1 parent 0e60964 commit 200978f

File tree

3 files changed

+45
-26
lines changed

3 files changed

+45
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ script:
8989
- '[[ ! -z "${local_config}" ]] && docker exec ${container_id} bash -c "cp ${DRUPALVM_DIR}/${local_config} ${config_dir:-$DRUPALVM_DIR}/local.config.yml" || true'
9090

9191
# Vagrantfile syntax check.
92-
- 'rubocop ./Vagrantfile --except LineLength,Eval,MutableConstant,BlockLength'
92+
- 'rubocop ./Vagrantfile ./lib/drupalvm --except LineLength,Eval,MutableConstant,BlockLength,ConditionalAssignment,IndentArray,AlignParameters'
9393

9494
# Ansible syntax check.
9595
- 'docker exec --tty ${container_id} env TERM=xterm ansible-playbook ${DRUPALVM_DIR}/provisioning/playbook.yml --syntax-check'

Vagrantfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ guest_config_dir = ENV['DRUPALVM_CONFIG_DIR'] ? "/vagrant/#{ENV['DRUPALVM_CONFIG
1515

1616
drupalvm_env = ENV['DRUPALVM_ENV'] || 'vagrant'
1717

18+
default_config_file = "#{host_drupalvm_dir}/default.config.yml"
19+
unless File.exist?(default_config_file)
20+
raise_message "Configuration file not found! Expected in #{default_config_file}"
21+
end
22+
1823
vconfig = load_config([
19-
"#{host_drupalvm_dir}/default.config.yml",
24+
default_config_file,
2025
"#{host_config_dir}/config.yml",
2126
"#{host_config_dir}/local.config.yml",
22-
"#{host_config_dir}/#{drupalvm_env}.config.yml",
27+
"#{host_config_dir}/#{drupalvm_env}.config.yml"
2328
])
2429

25-
provisioner = vconfig['force_ansible_local'] ? :ansible_local : get_provisioner
30+
provisioner = vconfig['force_ansible_local'] ? :ansible_local : vagrant_provisioner
2631
if provisioner == :ansible
2732
playbook = "#{host_drupalvm_dir}/provisioning/playbook.yml"
2833
config_dir = host_config_dir
@@ -45,7 +50,7 @@ Vagrant.configure('2') do |config|
4550
ip: vconfig['vagrant_ip'],
4651
auto_network: vconfig['vagrant_ip'] == '0.0.0.0' && Vagrant.has_plugin?('vagrant-auto_network')
4752

48-
if !vconfig['vagrant_public_ip'].empty?
53+
unless vconfig['vagrant_public_ip'].empty?
4954
config.vm.network :public_network,
5055
ip: vconfig['vagrant_public_ip'] != '0.0.0.0' ? vconfig['vagrant_public_ip'] : nil
5156
end

lib/drupalvm/vagrant.rb

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,43 +45,57 @@ def load_config(files)
4545
resolve_jinja_variables(vconfig)
4646
end
4747

48+
# Return the path to the ansible-playbook executable.
49+
def ansible_bin
50+
@ansible_bin ||= which('ansible-playbook')
51+
end
4852

4953
# Return the ansible version parsed from running the executable path provided.
50-
def get_ansible_version(exe)
51-
/^[^\s]+ (.+)$/.match(`#{exe} --version`) { |match| return match[1] }
54+
def ansible_version
55+
/^[^\s]+ (.+)$/.match(`#{ansible_bin} --version`) { |match| return match[1] }
5256
end
5357

5458
# Require that if installed, the ansible version meets the requirements.
5559
def require_ansible_version(requirement)
56-
if !(ansible_bin = which('ansible-playbook'))
57-
return
58-
end
59-
ansible_version = get_ansible_version(ansible_bin)
60+
return unless ansible_bin
6061
req = Gem::Requirement.new(requirement)
61-
if req.satisfied_by?(Gem::Version.new(ansible_version))
62-
return
63-
end
64-
raise Vagrant::Errors::VagrantError.new, "You must install an Ansible version #{requirement} to use this version of Drupal VM."
62+
return if req.satisfied_by?(Gem::Version.new(ansible_version))
63+
raise_message "You must install an Ansible version #{requirement} to use this version of Drupal VM."
64+
end
65+
66+
def raise_message(msg)
67+
raise Vagrant::Errors::VagrantError.new, msg
6568
end
6669

6770
# Return which Vagrant provisioner to use.
68-
def get_provisioner
69-
which('ansible-playbook') ? :ansible : :ansible_local
71+
def vagrant_provisioner
72+
ansible_bin ? :ansible : :ansible_local
73+
end
74+
75+
def get_apache_vhosts(vhosts)
76+
aliases = []
77+
vhosts.each do |host|
78+
aliases.push(host['servername'])
79+
aliases.concat(host['serveralias'].split) if host['serveralias']
80+
end
81+
aliases
82+
end
83+
84+
def get_nginx_vhosts(vhosts)
85+
aliases = []
86+
vhosts.each do |host|
87+
aliases.push(host['server_name'])
88+
aliases.concat(host['server_name_redirect'].split) if host['server_name_redirect']
89+
end
90+
aliases
7091
end
7192

7293
# Return a list of all virtualhost server names and aliases from a config hash.
7394
def get_vhost_aliases(vconfig)
74-
aliases = []
7595
if vconfig['drupalvm_webserver'] == 'apache'
76-
vconfig['apache_vhosts'].each do |host|
77-
aliases.push(host['servername'])
78-
aliases.concat(host['serveralias'].split) if host['serveralias']
79-
end
96+
aliases = get_apache_vhosts(vconfig['apache_vhosts'])
8097
else
81-
vconfig['nginx_hosts'].each do |host|
82-
aliases.concat(host['server_name'].split)
83-
aliases.concat(host['server_name_redirect'].split) if host['server_name_redirect']
84-
end
98+
aliases = get_nginx_vhosts(vconfig['nginx_hosts'])
8599
end
86100
aliases = aliases.uniq - [vconfig['vagrant_ip']]
87101
# Remove wildcard subdomains.

0 commit comments

Comments
 (0)