Class: Hcloud::IsoResource

Inherits:
AbstractResource show all
Defined in:
lib/hcloud/iso_resource.rb

Instance Attribute Summary

Attributes inherited from AbstractResource

#base_path, #client, #parent

Instance Method Summary collapse

Methods inherited from AbstractResource

#each, #initialize, #limit, #mj, #order, #page, #per_page

Constructor Details

This class inherits a constructor from Hcloud::AbstractResource

Instance Method Details

#[](arg) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hcloud/iso_resource.rb', line 9

def [](arg)
  case arg
  when Integer
    begin
      find(arg)
    rescue Error::NotFound
    end
  when String
    find_by(name: arg)
  end
end

#allObject



3
4
5
6
7
# File 'lib/hcloud/iso_resource.rb', line 3

def all
  mj("isos") do |j|
    j.flat_map{|x| x["isos"].map{ |x| Iso.new(x, self, client) } }
  end
end

#find(id) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/hcloud/iso_resource.rb', line 21

def find(id)
  Iso.new(
    Oj.load(request("isos/#{id.to_i}").run.body)["iso"],
    self,
    client
  )
end

#find_by(name:) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/hcloud/iso_resource.rb', line 29

def find_by(name:)
  j = Oj.load(request("isos", q: {name: name}).run.body)["isos"]
  return if j.none?
  j.each do |x|
    return Iso.new(x, self, client)
  end
end