module Landrush::Action::Common

A module containing shared functionality for Vagrant middleware classes

Constants

SUPPORTED_PROVIDERS

Public Class Methods

included(base) click to toggle source
# File lib/landrush/action/common.rb, line 15
def self.included(base)
  base.send :attr_reader, :app, :env
end
new(app, env) click to toggle source
# File lib/landrush/action/common.rb, line 19
def initialize(app, env)
  @app = app
  @env = env
end

Public Instance Methods

config() click to toggle source
# File lib/landrush/action/common.rb, line 60
def config
  if env.key? :global_config
    # < Vagrant 1.5
    env[:global_config].landrush
  else
    # >= Vagrant 1.5
    machine.config.landrush
  end
end
docker?() click to toggle source
# File lib/landrush/action/common.rb, line 24
def docker?
  provider == :docker
end
enabled?() click to toggle source
# File lib/landrush/action/common.rb, line 80
def enabled?
  config.enabled?
end
guest_redirect_dns?() click to toggle source
# File lib/landrush/action/common.rb, line 84
def guest_redirect_dns?
  config.guest_redirect_dns?
end
info(msg) click to toggle source
# File lib/landrush/action/common.rb, line 88
def info(msg)
  env[:ui].info "[landrush] #{msg}"
end
libvirt?() click to toggle source
# File lib/landrush/action/common.rb, line 32
def libvirt?
  provider == :libvirt
end
log(level, msg) click to toggle source
# File lib/landrush/action/common.rb, line 92
def log(level, msg)
  # Levels from github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb
  valid_levels = %i[ask detail warn error info output success]

  if valid_levels.include? level
    env[:ui].send level, "[landrush] #{msg}"
  else
    env[:ui].error "[landrush] (Invalid logging level #{level}) #{msg}"
  end
end
machine() click to toggle source
# File lib/landrush/action/common.rb, line 56
def machine
  env[:machine]
end
machine_hostname() click to toggle source
# File lib/landrush/action/common.rb, line 70
def machine_hostname
  @machine_hostname ||= read_machine_hostname
end
parallels?() click to toggle source
# File lib/landrush/action/common.rb, line 40
def parallels?
  provider == :parallels
end
provider() click to toggle source
# File lib/landrush/action/common.rb, line 44
def provider
  provider_name = SUPPORTED_PROVIDERS.fetch(machine.provider.class.name) do |key|
    raise "The landrush plugin does not support the #{key} provider yet!"
  end

  if provider_name == :parallels && Gem::Version.new(VagrantPlugins::Parallels::VERSION) < Gem::Version.new('1.0.3')
    raise "The landrush plugin supports the Parallels provider v1.0.3 and later. Please, update your 'vagrant-parallels' plugin."
  end

  provider_name
end
read_machine_hostname() click to toggle source
# File lib/landrush/action/common.rb, line 74
def read_machine_hostname
  return machine.config.vm.hostname if machine.config.vm.hostname

  "#{Pathname.pwd.basename}.#{config.tld_as_array[0]}"
end
virtualbox?() click to toggle source
# File lib/landrush/action/common.rb, line 28
def virtualbox?
  provider == :virtualbox
end
vmware?() click to toggle source
# File lib/landrush/action/common.rb, line 36
def vmware?
  provider == :vmware_fusion
end