Class: Vagrant::Action::Environment

Inherits:
Util::HashWithIndifferentAccess show all
Defined in:
lib/vagrant/action/environment.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Util::HashWithIndifferentAccess

#[], #[]=, #delete, #key?, #merge, #merge!, #values_at

Constructor Details

#initialize(env) ⇒ Environment

Returns a new instance of Environment.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vagrant/action/environment.rb', line 12

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
      value = eval("h.env.#{k}")
      h[k] = value
    rescue Exception
      nil
    end
  end

  @env = env
  @interrupted = false
end

Instance Attribute Details

#envObject (readonly)

The Environment object represented by this action environment.



10
11
12
# File 'lib/vagrant/action/environment.rb', line 10

def env
  @env
end

Instance Method Details

#interrupt!Object

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 Vagrant::Action when a SIGINT is captured.



37
38
39
# File 'lib/vagrant/action/environment.rb', line 37

def interrupt!
  @interrupted = true
end

#interrupted?Bool

Returns a boolean denoting if environment has been interrupted with a SIGINT.

Returns:

  • (Bool)


45
46
47
# File 'lib/vagrant/action/environment.rb', line 45

def interrupted?
  !!@interrupted
end

#uiObject

Returns a UI object from the environment



29
30
31
# File 'lib/vagrant/action/environment.rb', line 29

def ui
  env.ui
end