Class: Cloudfront::Helpers::CacheBehaviors

Inherits:
Object
  • Object
show all
Includes:
Utils::ConfigurationChecker, Utils::XmlSerializer
Defined in:
lib/cloudfront/helpers/cache_behaviors.rb

Instance Attribute Summary collapse

Attributes included from Utils::ConfigurationChecker

#error_messages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::XmlSerializer

#to_xml

Methods included from Utils::ConfigurationChecker

#check_configuration, #valid?

Constructor Details

#initialize(&block) ⇒ CacheBehaviors

Returns a new instance of CacheBehaviors.



14
15
16
17
18
19
20
# File 'lib/cloudfront/helpers/cache_behaviors.rb', line 14

def initialize(&block)
  #set default values
  @cache_behaviors = []

  #set values from block
  instance_eval &block if block_given?
end

Instance Attribute Details

#cache_behaviorsObject

Returns the value of attribute cache_behaviors.



12
13
14
# File 'lib/cloudfront/helpers/cache_behaviors.rb', line 12

def cache_behaviors
  @cache_behaviors
end

Class Method Details

.from_hash(hash) ⇒ Object

hash = { "CacheBehaviors" => { "Quantity" => "2", "Items" => { "CacheBehavior" => [ { #see CacheBehavior }, { #... } ] } } }



50
51
52
53
54
55
56
57
58
59
# File 'lib/cloudfront/helpers/cache_behaviors.rb', line 50

def self.from_hash(hash)
  hash = hash["CacheBehaviors"] || hash
  self.new do
    for cache_behavior in [(hash["Items"]|| {})["CacheBehavior"]]
      unless cache_behavior.nil?
        self.cache_behaviors.push(CacheBehavior.from_hash(cache_behavior))
      end
    end
  end
end

Instance Method Details

#build_xml(xml) ⇒ Object

The cache behavior class container 1 pattern that specifies files that this cache behavior applies to ID of the origin that this cache behavior applies to true | false all | whitelist | none number of cookie names to forward to origin name of a cookie to forward to the origin ... see TrustedSigners class allow-all | https-only minimum TTL in seconds for files specified by PathPattern



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cloudfront/helpers/cache_behaviors.rb', line 87

def build_xml(xml)
check_configuration
  xml.CacheBehaviors {
    xml.Quantity @cache_behaviors.size
    if @cache_behaviors.size > 0
      xml.Items {
        for cache_behavior in @cache_behaviors
          cache_behavior.build_xml(xml)
        end
      }
    end
  }
end

#validateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cloudfront/helpers/cache_behaviors.rb', line 22

def validate
  # some wrapping
  @cache_behaviors = Array.wrap @cache_behaviors

  # Error checking
  for cache_behavior in @cache_behaviors
    if cache_behavior.is_a?(CacheBehavior)
      cache_behavior.check_configuration
    else
      error_messages.push "cache_behaviors list contains a non CacheBehavior element #{cache_behavior}"
    end
  end
end