Class: Hcloud::PlacementGroupResource

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

Instance Attribute Summary

Attributes inherited from AbstractResource

#client

Instance Method Summary collapse

Methods inherited from AbstractResource

#all, bind_to, #each, filter_attributes, #find, #find_by, #initialize, #limit, #order, #page, #pagination, #per_page, resource, resource_class, resource_path, resource_url, #run, #where

Constructor Details

This class inherits a constructor from Hcloud::AbstractResource

Instance Method Details

#[](arg) ⇒ Object



9
10
11
12
13
# File 'lib/hcloud/placement_group_resource.rb', line 9

def [](arg)
  return find_by(name: arg) if arg.is_a?(String)

  super
end

#create(name:, type: 'spread', labels: {}) ⇒ Object

currently only spread is available



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hcloud/placement_group_resource.rb', line 16

def create(name:, type: 'spread', labels: {})
  if type.to_s != 'spread'
    raise Hcloud::Error::InvalidInput, "invalid type #{type.inspect}, only 'spread' is allowed"
  end
  raise Hcloud::Error::InvalidInput, 'no name given' if name.blank?

  prepare_request(
    'placement_groups', j: COLLECT_ARGS.call(__method__, binding),
                        expected_code: 201
  ) do |response|
    PlacementGroup.new(client, response.parsed_json[:placement_group])
  end
end