Sha256: c68ebd1d810d9cfc2d529fa58e1987aa63ef81f1d230aa115ea8674c2cd95924

Contents?: true

Size: 1.11 KB

Versions: 8

Compression:

Stored size: 1.11 KB

Contents

class Ey::Core::Client::AutoScalingPolicies < Ey::Core::Collection
  model Ey::Core::Client::BaseAutoScalingPolicy

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

  self.model_root         = "auto_scaling_policy"
  self.model_request      = :get_auto_scaling_policy
  self.collection_root    = "auto_scaling_policies"
  self.collection_request = :get_auto_scaling_policies

  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
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
ey-core-3.6.0.autoscaling1 lib/ey-core/collections/auto_scaling_policies.rb
ey-core-3.6.4 lib/ey-core/collections/auto_scaling_policies.rb
ey-core-3.6.3 lib/ey-core/collections/auto_scaling_policies.rb
ey-core-3.6.1 lib/ey-core/collections/auto_scaling_policies.rb
groove-ey-core-3.6.3 lib/ey-core/collections/auto_scaling_policies.rb
groove-ey-core-3.6.2 lib/ey-core/collections/auto_scaling_policies.rb
groove-ey-core-3.6.1 lib/ey-core/collections/auto_scaling_policies.rb
ey-core-3.5.0 lib/ey-core/collections/auto_scaling_policies.rb