Class: Ey::Core::Client::AutoScalingPolicies

Inherits:
Ey::Core::Collection show all
Defined in:
lib/ey-core/collections/auto_scaling_policies.rb

Constant Summary collapse

MODELS_TO_TYPE =
{
  "simple" => Ey::Core::Client::SimpleAutoScalingPolicy,
  "step"   => Ey::Core::Client::StepAutoScalingPolicy,
  "target" => Ey::Core::Client::TargetAutoScalingPolicy
}.freeze

Instance Method Summary collapse

Methods inherited from Ey::Core::Collection

#==, #all, #collection_request, #collection_root, #create!, #each_entry, #each_page, #first, #get, #get!, #last_page, #load, #model_request, #model_root, #new_page, #next_page, #one, #page_parameters, #perform_get, #previous_page

Instance Method Details

#new(attributes = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ey-core/collections/auto_scaling_policies.rb', line 15

def new(attributes = {})
  unless attributes.is_a?(::Hash)
    raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
  end

  params = Cistern::Hash.stringify_keys(attributes)
  type = params["type"] ||= "simple"
  model = MODELS_TO_TYPE[type]
  unless model
    raise(ArgumentError.new("Unrecognized policy type #{type}. Allowed types are: #{MODELS_TO_TYPE.keys.join(', ')}"))
  end
  model.new(
    {
      :collection => self,
      :connection => connection,
    }.merge(params)
  )
end