Class: Cloudfront::Helpers::CacheBehaviors
- Inherits:
-
Object
- Object
- Cloudfront::Helpers::CacheBehaviors
- Includes:
- Utils::ConfigurationChecker, Utils::XmlSerializer
- Defined in:
- lib/cloudfront/helpers/cache_behaviors.rb
Instance Attribute Summary collapse
-
#cache_behaviors ⇒ Object
Returns the value of attribute cache_behaviors.
Attributes included from Utils::ConfigurationChecker
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
hash = { “CacheBehaviors” => { “Quantity” => “2”, “Items” => { “CacheBehavior” => [ { #see CacheBehavior }, { #… } ] } } }.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
The cache behavior class container <CacheBehaviors> <Quantity>1</Quantity> <Items> <CacheBehavior> <PathPattern>pattern that specifies files that this cache behavior applies to</PathPattern> <TargetOriginId>ID of the origin that this cache behavior applies to</TargetOriginId> <ForwardedValues> <QueryString>true | false</QueryString> <Cookies> <Forward>all | whitelist | none</Forward> <!– Required when Forward = whitelist, omitted otherwise.
-
#initialize(&block) ⇒ CacheBehaviors
constructor
A new instance of CacheBehaviors.
- #validate ⇒ Object
Methods included from Utils::XmlSerializer
Methods included from Utils::ConfigurationChecker
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_behaviors ⇒ Object
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 <CacheBehaviors>
<Quantity>1</Quantity>
<Items>
<CacheBehavior>
<PathPattern>pattern that specifies files that this cache behavior applies to</PathPattern>
<TargetOriginId>ID of the origin that this cache behavior applies to</TargetOriginId>
<ForwardedValues>
<QueryString>true | false</QueryString>
<Cookies>
<Forward>all | whitelist | none</Forward>
<!-- Required when Forward = whitelist, omitted otherwise. -->
<WhitelistedNames>
<Quantity>number of cookie names to forward to origin</Quantity>
<Items>
<Name>name of a cookie to forward to the origin</Name>
</Items>
</WhitelistedNames>
</Cookies>
</ForwardedValues>
<TrustedSigners>
... see TrustedSigners class
</TrustedSigners>
<ViewerProtocolPolicy>allow-all | https-only</ViewerProtocolPolicy>
<MinTTL>minimum TTL in seconds for files specified by PathPattern</MinTTL>
</CacheBehavior>
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 |
#validate ⇒ Object
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 .push "cache_behaviors list contains a non CacheBehavior element #{cache_behavior}" end end end |