Module: Landrush::Action::Common
- Included in:
- InstallPrerequisites, RedirectDns, Setup, Teardown
- Defined in:
- lib/landrush/action/common.rb
Constant Summary collapse
- SUPPORTED_PROVIDERS =
{ 'VagrantPlugins::ProviderVirtualBox::Provider' => :virtualbox, 'VagrantPlugins::ProviderLibvirt::Provider' => :libvirt, 'HashiCorp::VagrantVMwarefusion::Provider' => :vmware_fusion, 'VagrantPlugins::Parallels::Provider' => :parallels, 'Landrush::FakeProvider' => :fake_provider }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #enabled? ⇒ Boolean
- #guest_redirect_dns? ⇒ Boolean
- #handle_action_stack(env) ⇒ Object
- #info(msg) ⇒ Object
- #initialize(app, env) ⇒ Object
- #libvirt? ⇒ Boolean
- #log(level, msg) ⇒ Object
- #machine ⇒ Object
- #machine_hostname ⇒ Object
- #parallels? ⇒ Boolean
- #provider ⇒ Object
- #read_machine_hostname ⇒ Object
- #virtualbox? ⇒ Boolean
- #vmware? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
12 13 14 |
# File 'lib/landrush/action/common.rb', line 12 def self.included(base) base.send :attr_reader, :app, :env end |
Instance Method Details
#config ⇒ Object
60 61 62 63 64 65 66 67 68 |
# 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 |
#enabled? ⇒ Boolean
82 83 84 |
# File 'lib/landrush/action/common.rb', line 82 def enabled? config.enabled? end |
#guest_redirect_dns? ⇒ Boolean
86 87 88 |
# File 'lib/landrush/action/common.rb', line 86 def guest_redirect_dns? config.guest_redirect_dns? end |
#handle_action_stack(env) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/landrush/action/common.rb', line 20 def handle_action_stack(env) @env = env yield app.call(env) end |
#info(msg) ⇒ Object
90 91 92 |
# File 'lib/landrush/action/common.rb', line 90 def info(msg) env[:ui].info "[landrush] #{msg}" end |
#initialize(app, env) ⇒ Object
16 17 18 |
# File 'lib/landrush/action/common.rb', line 16 def initialize(app, env) @app = app end |
#libvirt? ⇒ Boolean
32 33 34 |
# File 'lib/landrush/action/common.rb', line 32 def libvirt? provider == :libvirt end |
#log(level, msg) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/landrush/action/common.rb', line 94 def log(level, msg) # Levels from github.com/mitchellh/vagrant/blob/master/lib/vagrant/ui.rb valid_levels = [: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 ⇒ Object
56 57 58 |
# File 'lib/landrush/action/common.rb', line 56 def machine env[:machine] end |
#machine_hostname ⇒ Object
70 71 72 |
# File 'lib/landrush/action/common.rb', line 70 def machine_hostname @machine_hostname ||= read_machine_hostname end |
#parallels? ⇒ Boolean
40 41 42 |
# File 'lib/landrush/action/common.rb', line 40 def parallels? provider == :parallels end |
#provider ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/landrush/action/common.rb', line 74 def read_machine_hostname if machine.config.vm.hostname return machine.config.vm.hostname end "#{Pathname.pwd.basename}.#{config.tld}" end |
#virtualbox? ⇒ Boolean
28 29 30 |
# File 'lib/landrush/action/common.rb', line 28 def virtualbox? provider == :virtualbox end |
#vmware? ⇒ Boolean
36 37 38 |
# File 'lib/landrush/action/common.rb', line 36 def vmware? provider == :vmware_fusion end |