Class: Vagrant::Plugin::V2::Trigger
- Inherits:
-
Object
- Object
- Vagrant::Plugin::V2::Trigger
- Defined in:
- lib/vagrant/plugin/v2/trigger.rb
Instance Attribute Summary collapse
- #config ⇒ Kernel_V2::Config::Trigger readonly
Instance Method Summary collapse
-
#fire_triggers(action, stage, guest_name, type) ⇒ Object
Fires all triggers, if any are defined for the action and guest.
-
#initialize(env, config, machine, ui) ⇒ Trigger
constructor
This class is responsible for setting up basic triggers that were defined inside a Vagrantfile.
Constructor Details
#initialize(env, config, machine, ui) ⇒ Trigger
This class is responsible for setting up basic triggers that were defined inside a Vagrantfile.
24 25 26 27 28 29 30 31 |
# File 'lib/vagrant/plugin/v2/trigger.rb', line 24 def initialize(env, config, machine, ui) @env = env @config = config @machine = machine @ui = ui @logger = Log4r::Logger.new("vagrant::trigger::#{self.class.to_s.downcase}") end |
Instance Attribute Details
#config ⇒ Kernel_V2::Config::Trigger (readonly)
15 16 17 |
# File 'lib/vagrant/plugin/v2/trigger.rb', line 15 def config @config end |
Instance Method Details
#fire_triggers(action, stage, guest_name, type) ⇒ Object
Fires all triggers, if any are defined for the action and guest. Returns early
and logs a warning if the community plugin vagrant-triggers
is installed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vagrant/plugin/v2/trigger.rb', line 39 def fire_triggers(action, stage, guest_name, type) if community_plugin_detected? @logger.warn("Community plugin `vagrant-triggers detected, so core triggers will not fire") return end if !action @logger.warn("Action given is nil, no triggers will fire") return else action = action.to_sym end # get all triggers matching action triggers = [] if stage == :before triggers = config.before_triggers.select do |t| t.command == action || (t.command == :all && !t.ignore.include?(action)) end elsif stage == :after triggers = config.after_triggers.select do |t| t.command == action || (t.command == :all && !t.ignore.include?(action)) end else raise Errors::TriggersNoStageGiven, action: action, stage: stage, guest_name: guest_name end triggers = filter_triggers(triggers, guest_name, type) if !triggers.empty? @logger.info("Firing trigger for action #{action} on guest #{guest_name}") @ui.info(I18n.t("vagrant.trigger.start", type: type, stage: stage, action: action)) fire(triggers, guest_name) end end |