Class: VagrantPlugins::DigitalOcean::Actions::ReadState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-digitalocean/actions/read_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



7
8
9
10
# File 'lib/vagrant-digitalocean/actions/read_state.rb', line 7

def initialize(app, env)
  @app, @env = app, env
  @client = Helpers::Client.new
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-digitalocean/actions/read_state.rb', line 12

def call(env)
  # If we have a machine id ask the api what the state is
  if env[:machine].id
    droplet = @client.request("/droplets/#{env[:machine].id}")["droplet"]

    env[:machine_state] = droplet
  end

  # no id signals that the machine hasn't yet been created
  env[:machine_state] ||= {"status" => :not_created}

  # TODO there has to be a better way, see UP for when
  # :machine_just_created is set
  env[:machine_state][:just_created] = env[:machine_just_created]
  @app.call(env)
end