Class: VagrantPlugins::Linode::Helpers::Result

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Result

Returns a new instance of Result.



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

def initialize(body)
  @result = body
end

Instance Method Details

#[](key) ⇒ Object



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

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

#error(sub_obj, key, value) ⇒ Object



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

def error(sub_obj, key, value)
  fail(Errors::ResultMatchErro r, 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-linode/helpers/result.rb', line 17

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

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

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

#find_id(sub_obj, search) ⇒ Object

:ssh_keys, => ‘ijin (vagrant)’



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

def find_id(sub_obj, search) #:ssh_keys, {:name => 'ijin (vagrant)'}
  find(sub_obj, search)['id']
end