Class: Vagrant::Action::Builtin::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/builtin/trigger.rb

Overview

This class is used within the Builder class for injecting triggers into different parts of the call stack.

Instance Method Summary collapse

Constructor Details

#initialize(app, env, name, triggers, timing, type = :action, all: false) ⇒ Trigger

Returns a new instance of Trigger.

Parameters:

  • name (Class, String, Symbol)

    Name of trigger to fire

  • triggers (Vagrant::Plugin::V2::Triger)

    Trigger object

  • timing (Symbol)

    When trigger should fire (:before/:after)

  • type (Symbol) (defaults to: :action)

    Type of trigger


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/vagrant/action/builtin/trigger.rb', line 11

def initialize(app, env, name, triggers, timing, type=:action, all: false)
  @app         = app
  @env         = env
  @triggers    = triggers
  @name        = name
  @timing      = timing
  @type        = type
  @all         = all

  if ![:before, :after].include?(timing)
    raise ArgumentError,
      "Invalid value provided for `timing` (allowed: :before or :after)"
  end
end

Instance Method Details

#call(env) ⇒ Object


26
27
28
29
30
31
32
33
# File 'lib/vagrant/action/builtin/trigger.rb', line 26

def call(env)
  machine = env[:machine]
  machine_name = machine.name if machine

  @triggers.fire(@name, @timing, machine_name, @type, all: @all)
  # Carry on
  @app.call(env)
end