Class: Hcloud::IsoResource
Instance Attribute Summary
#base_path, #client, #parent
Instance Method Summary
collapse
#each, #initialize, #limit, #mj, #order, #page, #per_page
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
|
#all ⇒ Object
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
|