Class: VagrantPlugins::DigitalOcean::Helpers::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-digitalocean/helpers/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Result

Returns a new instance of Result.



5
6
7
# File 'lib/vagrant-digitalocean/helpers/result.rb', line 5

def initialize(body)
  @result = body
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
# File 'lib/vagrant-digitalocean/helpers/result.rb', line 9

def [](key)
  @result[key.to_s]
end

#error(sub_obj, key, value) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/vagrant-digitalocean/helpers/result.rb', line 29

def error(sub_obj, key, value)
  raise(Errors::ResultMatchError, {
   :key => key,
   :value => value,
   :collection_name => sub_obj.to_s,
   :sub_obj => @result[sub_obj.to_s]
  })
end

#find(sub_obj, search) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-digitalocean/helpers/result.rb', line 17

def find(sub_obj, search)
  key = search.keys.first
  value = search[key].to_s
  key = key.to_s

  result = @result[sub_obj.to_s].inject(nil) do |result, obj|
    obj[key] == value ? obj : result
  end

  result || error(sub_obj, key, value)
end

#find_id(sub_obj, search) ⇒ Object



13
14
15
# File 'lib/vagrant-digitalocean/helpers/result.rb', line 13

def find_id(sub_obj, search)
  find(sub_obj, search)["id"]
end