Class: VagrantPlugins::BetterHosts::Action::BaseAction

Inherits:
Object
  • Object
show all
Includes:
BetterHosts
Defined in:
lib/vagrant-betterhosts/Action/BaseAction.rb

Overview

Extend it!

Direct Known Subclasses

RemoveHosts, UpdateHosts

Constant Summary collapse

@@completed =

Vagrant 2.2.14 has changed the hooks execution policy so they started to be triggered more than once (a lot actually) which is non-performant and floody. With this static property, we control the executions and allowing just one.

{}

Instance Method Summary collapse

Methods included from BetterHosts

#add_betterhost_entries, #add_host_entries, #check_hostnames_to_add, #disable_clean, #generate_hostnames_by_ips, #get_clean_parameter_by_system, #get_cli, #get_hostnames, #get_ips, #get_os_binary, #print_readme, #remove_betterhost_entries, #remove_host_entries

Constructor Details

#initialize(app, env) ⇒ BaseAction

Returns a new instance of BaseAction.



19
20
21
22
23
# File 'lib/vagrant-betterhosts/Action/BaseAction.rb', line 19

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @ui = env[:ui]
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagrant-betterhosts/Action/BaseAction.rb', line 25

def call(env)
  # Check whether the plugin has been executed for a particular
  # VM as it may happen that a single Vagrantfile defines multiple
  # machines and having a static flag will result in a plugin being
  # executed just once.
  # https://github.com/goodhosts/vagrant/issues/30
  @@completed[@machine.name] = [] unless @@completed.key?(@machine.name)
  unless @@completed[@machine.name].include? self.class.name
    run(env)
    @@completed[@machine.name] << self.class.name
  end

  @app.call(env)
end

#run(_env) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/vagrant-betterhosts/Action/BaseAction.rb', line 40

def run(_env)
  raise NotImplementedError.new("Must be implemented!")
end