Action environment hash has indifferent access
This commit is contained in:
parent
a0fa3755b5
commit
892a624756
|
@ -49,6 +49,44 @@ module Vagrant
|
|||
def error?
|
||||
!error.nil?
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# Hash with indifferent access
|
||||
#-----------------------------------------------------------------
|
||||
def [](key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
super(convert_key(key), value)
|
||||
end
|
||||
|
||||
def delete(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def values_at(*indices)
|
||||
indices.collect { |key| self[convert_key(key)] }
|
||||
end
|
||||
|
||||
def merge(other)
|
||||
dup.merge!(other)
|
||||
end
|
||||
|
||||
def merge!(other)
|
||||
other.each do |key, value|
|
||||
self[convert_key(key)] = value
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def has_key?(key)
|
||||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def convert_key(key)
|
||||
key.is_a?(Symbol) ? key.to_s : key
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ module Vagrant
|
|||
|
||||
def call(env)
|
||||
if env["vm"].vm.running?
|
||||
if !env[:force]
|
||||
if !env["force"]
|
||||
catch_action_exception(env) { env["vm"].system.halt }
|
||||
return if env.error?
|
||||
end
|
||||
|
|
|
@ -28,4 +28,12 @@ class ActionEnvironmentTest < Test::Unit::TestCase
|
|||
@instance.error!(:key)
|
||||
assert @instance.error?
|
||||
end
|
||||
|
||||
should "have indifferent access" do
|
||||
@instance[:foo] = :bar
|
||||
@instance["bar"] = :baz
|
||||
|
||||
assert_equal :bar, @instance["foo"]
|
||||
assert_equal :baz, @instance[:bar]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue