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

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

Instance Method Summary collapse

Methods included from Helpers::Client

#client

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



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

def initialize(app, env)
  @app, @env = app, env
  @client = client
end

Instance Method Details

#call(env) ⇒ Object



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

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