Class: VagrantPlugins::Triggers::Config::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-triggers/config/trigger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrigger

Returns a new instance of Trigger.



7
8
9
10
11
# File 'lib/vagrant-triggers/config/trigger.rb', line 7

def initialize
  @blacklist = []
  @options   = { :good_exit => [0], :stderr => true, :stdout => true }
  @triggers  = []
end

Instance Attribute Details

#triggersObject (readonly)

Returns the value of attribute triggers.



5
6
7
# File 'lib/vagrant-triggers/config/trigger.rb', line 5

def triggers
  @triggers
end

Instance Method Details

#after(actions, options = {}, &block) ⇒ Object



13
14
15
# File 'lib/vagrant-triggers/config/trigger.rb', line 13

def after(actions, options = {}, &block)
  add_trigger(actions, :after, options, block)
end

#before(actions, options = {}, &block) ⇒ Object



17
18
19
# File 'lib/vagrant-triggers/config/trigger.rb', line 17

def before(actions, options = {}, &block)
  add_trigger(actions, :before, options, block)
end

#blacklist(actions = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/vagrant-triggers/config/trigger.rb', line 21

def blacklist(actions = nil)
  if actions
    Array(actions).each { |action| @blacklist << action.to_s }
    @blacklist.uniq!
  end
  @blacklist
end

#instead_of(actions, options = {}, &block) ⇒ Object Also known as: reject



29
30
31
# File 'lib/vagrant-triggers/config/trigger.rb', line 29

def instead_of(actions, options = {}, &block)
  add_trigger(actions, :instead_of, options, block)
end

#merge(other) ⇒ Object



34
35
36
37
38
39
# File 'lib/vagrant-triggers/config/trigger.rb', line 34

def merge(other)
  super.tap do |result|
    result.instance_variable_set(:@blacklist, @blacklist + other.blacklist)
    result.instance_variable_set(:@triggers, @triggers + other.triggers)
  end
end

#validate(machine) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/vagrant-triggers/config/trigger.rb', line 41

def validate(machine)
  errors = []

  if @__invalid_methods && !@__invalid_methods.empty?
    errors << I18n.t("vagrant.config.common.bad_field", :fields => @__invalid_methods.to_a.sort.join(", "))
  end

  { "triggers" => errors }
end