class Fog::AWS::ELB::Policies

Public Instance Methods

all(options={}) click to toggle source
# File lib/fog/aws/models/elb/policies.rb, line 12
def all(options={})
  merge_attributes(options)

  requires :load_balancer_id

  data = service.describe_load_balancer_policies(self.load_balancer_id).
    body["DescribeLoadBalancerPoliciesResult"]["PolicyDescriptions"]

  load(munge(data))
end
get(id) click to toggle source
# File lib/fog/aws/models/elb/policies.rb, line 23
def get(id)
  all.find { |policy| id == policy.id }
end
new(attributes={}) click to toggle source
Calls superclass method
# File lib/fog/aws/models/elb/policies.rb, line 27
def new(attributes={})
  super(self.attributes.merge(attributes))
end

Private Instance Methods

munge(data) click to toggle source
# File lib/fog/aws/models/elb/policies.rb, line 33
def munge(data)
  data.reduce([]) { |m,e|
    policy_attribute_descriptions = e["PolicyAttributeDescriptions"]

    policy = {
      :id                => e["PolicyName"],
      :type_name         => e["PolicyTypeName"],
      :policy_attributes => policy_attributes(policy_attribute_descriptions),
      :load_balancer_id  => self.load_balancer_id,
    }

    case e["PolicyTypeName"]
    when 'AppCookieStickinessPolicyType'
      cookie_name = policy_attribute_descriptions.find{|h| h['AttributeName'] == 'CookieName'}['AttributeValue']
      policy['CookieName'] = cookie_name if cookie_name
    when 'LBCookieStickinessPolicyType'
      cookie_expiration_period = policy_attribute_descriptions.find{|h| h['AttributeName'] == 'CookieExpirationPeriod'}['AttributeValue'].to_i
      policy['CookieExpirationPeriod'] = cookie_expiration_period if cookie_expiration_period > 0
    end

    m << policy
    m
  }
end
policy_attributes(policy_attribute_descriptions) click to toggle source
# File lib/fog/aws/models/elb/policies.rb, line 58
def policy_attributes(policy_attribute_descriptions)
  policy_attribute_descriptions.reduce({}){|m,e|
    m[e["AttributeName"]] = e["AttributeValue"]
    m
  }
end