core: allow custom callables in hooks
This commit is contained in:
parent
ec5727dfe0
commit
8d99382993
|
@ -62,10 +62,11 @@ module Vagrant
|
||||||
if enabled
|
if enabled
|
||||||
type_map = provisioner_type_map(env)
|
type_map = provisioner_type_map(env)
|
||||||
provisioner_instances(env).each do |p|
|
provisioner_instances(env).each do |p|
|
||||||
|
type_name = type_map[p]
|
||||||
next if env[:provision_types] && \
|
next if env[:provision_types] && \
|
||||||
!env[:provision_types].include?(type_map[p])
|
!env[:provision_types].include?(type_name)
|
||||||
|
|
||||||
run_provisioner(env, type_map[p].to_s, p)
|
run_provisioner(env, type_name.to_s, p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -275,12 +275,12 @@ module Vagrant
|
||||||
# @param [Action::Runner] action_runner A custom action runner for running hooks.
|
# @param [Action::Runner] action_runner A custom action runner for running hooks.
|
||||||
def hook(name, opts=nil)
|
def hook(name, opts=nil)
|
||||||
@logger.info("Running hook: #{name}")
|
@logger.info("Running hook: #{name}")
|
||||||
callable = Action::Builder.new
|
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
|
opts[:callable] ||= Action::Builder.new
|
||||||
opts[:runner] ||= action_runner
|
opts[:runner] ||= action_runner
|
||||||
opts[:action_name] = name
|
opts[:action_name] = name
|
||||||
opts[:env] = self
|
opts[:env] = self
|
||||||
opts.delete(:runner).run(callable, opts)
|
opts.delete(:runner).run(opts.delete(:callable), opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
# This returns a machine with the proper provider for this environment.
|
# This returns a machine with the proper provider for this environment.
|
||||||
|
|
|
@ -324,6 +324,14 @@ describe Vagrant::Environment do
|
||||||
|
|
||||||
instance.hook(:foo, foo: :bar)
|
instance.hook(:foo, foo: :bar)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should allow passing a custom callable" do
|
||||||
|
instance.action_runner.should_receive(:run).with do |callable, env|
|
||||||
|
callable.should == :what
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.hook(:foo, callable: :what)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "primary machine name" do
|
describe "primary machine name" do
|
||||||
|
|
Loading…
Reference in New Issue