lib/hcloud/location_resource.rb in hcloud-0.1.1 vs lib/hcloud/location_resource.rb in hcloud-0.1.2
- old
+ new
@@ -1,38 +1,37 @@
module Hcloud
class LocationResource < AbstractResource
def all
- mj("locations") do |j|
- j.flat_map{|x| x["locations"].map{ |x| Location.new(x, self, client) } }
+ mj('locations') do |j|
+ j.flat_map { |x| x['locations'].map { |x| Location.new(x, self, client) } }
end
end
def find(id)
Location.new(
- Oj.load(request("locations/#{id}").run.body)["location"],
+ Oj.load(request("locations/#{id}").run.body)['location'],
self,
client
)
end
-
+
def find_by(name:)
- x = Oj.load(request("locations", q: {name: name}).run.body)["locations"]
+ x = Oj.load(request('locations', q: { name: name }).run.body)['locations']
return nil if x.none?
x.each do |s|
return Location.new(s, self, client)
end
end
-
+
def [](arg)
case arg
when Integer
- begin
- find(arg)
- rescue Error::NotFound
- end
+ begin
+ find(arg)
+ rescue Error::NotFound
+ end
when String
find_by(name: arg)
end
end
-
end
end