Class: VagrantPlugins::Triggers::Config::Trigger
- Inherits:
-
Object
- Object
- VagrantPlugins::Triggers::Config::Trigger
- Defined in:
- lib/vagrant-triggers/config/trigger.rb
Instance Attribute Summary collapse
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
Instance Method Summary collapse
- #after(actions, options = {}, &block) ⇒ Object
- #before(actions, options = {}, &block) ⇒ Object
- #blacklist(actions = nil) ⇒ Object
-
#initialize ⇒ Trigger
constructor
A new instance of Trigger.
- #instead_of(actions, options = {}, &block) ⇒ Object (also: #reject)
- #merge(other) ⇒ Object
- #validate(machine) ⇒ Object
Constructor Details
#initialize ⇒ Trigger
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
#triggers ⇒ Object (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, = {}, &block) add_trigger(actions, :after, , block) end |
#before(actions, options = {}, &block) ⇒ Object
17 18 19 |
# File 'lib/vagrant-triggers/config/trigger.rb', line 17 def before(actions, = {}, &block) add_trigger(actions, :before, , 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, = {}, &block) add_trigger(actions, :instead_of, , 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 |