lib/vagrant/action/environment.rb in vagrant-0.5.4 vs lib/vagrant/action/environment.rb in vagrant-0.6.0
- old
+ new
@@ -2,19 +2,15 @@
class Action
# Represents an action environment which is what is passed
# to the `call` method of each action. This environment contains
# some helper methods for accessing the environment as well
# as being a hash, to store any additional options.
- class Environment < Hash
+ class Environment < Util::HashWithIndifferentAccess
# The {Vagrant::Environment} object represented by this
# action environment.
attr_reader :env
- # If nonnil, the error associated with this environment. Set
- # using {#error!}
- attr_reader :error
-
def initialize(env)
super() do |h,k|
# By default, try to find the key as a method on the
# environment. Gross eval use here.
begin
@@ -24,75 +20,31 @@
nil
end
end
@env = env
- @error = nil
+ @interrupted = false
end
- # Returns a logger associated with the environment.
- def logger
- env.logger
+ # Returns a UI object from the environment
+ def ui
+ env.ui
end
- # Flags the environment as erroneous. Stores the given key
- # and options until the end of the action sequence.
- #
- # @param [Symbol] key Key to translation to display error message.
- # @param [Hash] options Variables to pass to the translation
- def error!(key, options=nil)
- @error = [key, (options || {})]
+ # Marks an environment as interrupted (by an outside signal or
+ # anything). This will trigger any middleware sequences using this
+ # environment to halt. This is automatically set by {Action} when
+ # a SIGINT is captured.
+ def interrupt!
+ @interrupted = true
end
- # Returns boolean denoting if environment is in erroneous state.
- #
- # @return [Boolean]
- def error?
- !error.nil?
- end
-
# Returns a boolean denoting if environment has been interrupted
# with a SIGINT.
+ #
+ # @return [Bool]
def interrupted?
- error? && error.first == :interrupt
- 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
+ !!@interrupted
end
end
end
end