Rename action registry to just Vagrant::Registry
This commit is contained in:
parent
ad03163eff
commit
e201d9cacf
|
@ -30,6 +30,7 @@ module Vagrant
|
|||
autoload :Errors, 'vagrant/errors'
|
||||
autoload :Hosts, 'vagrant/hosts'
|
||||
autoload :Plugin, 'vagrant/plugin'
|
||||
autoload :Registry, 'vagrant/registry'
|
||||
autoload :SSH, 'vagrant/ssh'
|
||||
autoload :TestHelpers, 'vagrant/test_helpers'
|
||||
autoload :UI, 'vagrant/ui'
|
||||
|
|
|
@ -4,7 +4,6 @@ require 'vagrant/action/builtin'
|
|||
module Vagrant
|
||||
module Action
|
||||
autoload :Environment, 'vagrant/action/environment'
|
||||
autoload :Registry, 'vagrant/action/registry'
|
||||
autoload :Runner, 'vagrant/action/runner'
|
||||
autoload :Warden, 'vagrant/action/warden'
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
module Vagrant
|
||||
module Action
|
||||
# This is the action registry, which stores action steps indexed
|
||||
# by a unique name. These registry names can be used to call actions
|
||||
# via the `Runner` class.
|
||||
class Registry
|
||||
def initialize
|
||||
@actions = {}
|
||||
end
|
||||
|
||||
# Register a callable by key.
|
||||
#
|
||||
# The callable should be given in a block which will be lazily evaluated
|
||||
# when the action is needed.
|
||||
#
|
||||
# If an action by the given name already exists then it will be
|
||||
# overwritten.
|
||||
def register(key, &block)
|
||||
@actions[key] = block
|
||||
end
|
||||
|
||||
# Get an action by the given key.
|
||||
#
|
||||
# This will evaluate the block given to `register` and return the resulting
|
||||
# action stack.
|
||||
def get(key)
|
||||
return nil if !@actions.has_key?(key)
|
||||
@actions[key].call
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -200,13 +200,13 @@ module Vagrant
|
|||
|
||||
# Action registry for registering new actions with this environment.
|
||||
#
|
||||
# @return [Action::Registry]
|
||||
# @return [Registry]
|
||||
def action_registry
|
||||
return @action_registry if defined?(@action_registry)
|
||||
|
||||
# The action registry hasn't been loaded yet, so load it
|
||||
# and setup the built-in actions with it.
|
||||
@action_registry = Action::Registry.new
|
||||
@action_registry = Registry.new
|
||||
Vagrant::Action.builtin!(@action_registry)
|
||||
@action_registry
|
||||
end
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
module Vagrant
|
||||
# Register components in a single location that can be queried.
|
||||
#
|
||||
# This allows certain components (such as guest systems, configuration
|
||||
# pieces, etc.) to be registered and queried.
|
||||
class Registry
|
||||
def initialize
|
||||
@actions = {}
|
||||
end
|
||||
|
||||
# Register a callable by key.
|
||||
#
|
||||
# The callable should be given in a block which will be lazily evaluated
|
||||
# when the action is needed.
|
||||
#
|
||||
# If an action by the given name already exists then it will be
|
||||
# overwritten.
|
||||
def register(key, &block)
|
||||
@actions[key] = block
|
||||
end
|
||||
|
||||
# Get an action by the given key.
|
||||
#
|
||||
# This will evaluate the block given to `register` and return the resulting
|
||||
# action stack.
|
||||
def get(key)
|
||||
return nil if !@actions.has_key?(key)
|
||||
@actions[key].call
|
||||
end
|
||||
end
|
||||
end
|
|
@ -78,7 +78,7 @@ describe Vagrant::Environment do
|
|||
|
||||
describe "action registry" do
|
||||
it "has an action registry" do
|
||||
instance.action_registry.should be_kind_of(Vagrant::Action::Registry)
|
||||
instance.action_registry.should be_kind_of(Vagrant::Registry)
|
||||
end
|
||||
|
||||
it "should have the built-in actions in the registry" do
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require File.expand_path("../../../base", __FILE__)
|
||||
require File.expand_path("../../base", __FILE__)
|
||||
|
||||
describe Vagrant::Action::Registry do
|
||||
describe Vagrant::Registry do
|
||||
let(:instance) { described_class.new }
|
||||
|
||||
it "should return nil for nonexistent actions" do
|
||||
it "should return nil for nonexistent items" do
|
||||
instance.get("foo").should be_nil
|
||||
end
|
||||
|
||||
it "should register an action without calling the block yet" do
|
||||
it "should register an item without calling the block yet" do
|
||||
expect do
|
||||
instance.register("foo") do
|
||||
raise Exception, "BOOM!"
|
||||
|
@ -15,7 +15,7 @@ describe Vagrant::Action::Registry do
|
|||
end.to_not raise_error
|
||||
end
|
||||
|
||||
it "should call and return the result of a block when asking for the action" do
|
||||
it "should call and return the result of a block when asking for the ite" do
|
||||
object = Object.new
|
||||
instance.register("foo") do
|
||||
object
|
Loading…
Reference in New Issue