Class: Cloudfront::Helpers::Origins
- Inherits:
-
Object
- Object
- Cloudfront::Helpers::Origins
- Includes:
- Utils::ConfigurationChecker, Utils::XmlSerializer
- Defined in:
- lib/cloudfront/helpers/origins.rb
Instance Attribute Summary collapse
-
#origins ⇒ Object
Returns the value of attribute origins.
Attributes included from Utils::ConfigurationChecker
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
{ “Origins” => { “Quantity” => “2”, “Items” => { “Origin” => [ { “Id” => “example-Amazon S3-origin”, “DomainName” => “myawsbucket.s3.amazonaws.com”, “S3OriginConfig” => { “OriginAccessIdentity” => “origin-access-identity/cloudfront/E74FTE3AEXAMPLE” } }, { “Id” => “example-custom-origin”, “DomainName” => “example.com”, “CustomOriginConfig” => { “HTTPPort” => “80”, “HTTPSPort” => “443”, “OriginProtocolPolicy” => “match-viewer” } } ] } } }.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
<Origins> <Quantity>number of origins</Quantity> <Items> …
-
#initialize(&block) ⇒ Origins
constructor
A new instance of Origins.
- #validate ⇒ Object
Methods included from Utils::XmlSerializer
Methods included from Utils::ConfigurationChecker
Constructor Details
#initialize(&block) ⇒ Origins
Returns a new instance of Origins.
13 14 15 16 17 18 19 |
# File 'lib/cloudfront/helpers/origins.rb', line 13 def initialize(&block) #set default values @origins = [] #set values from block instance_eval &block if block_given? end |
Instance Attribute Details
#origins ⇒ Object
Returns the value of attribute origins.
11 12 13 |
# File 'lib/cloudfront/helpers/origins.rb', line 11 def origins @origins end |
Class Method Details
.from_hash(hash) ⇒ Object
{
"Origins" => {
"Quantity" => "2",
"Items" => {
"Origin" => [
{
"Id" => "example-Amazon S3-origin",
"DomainName" => "myawsbucket.s3.amazonaws.com",
"S3OriginConfig" => {
"OriginAccessIdentity" => "origin-access-identity/cloudfront/E74FTE3AEXAMPLE"
}
},
{
"Id" => "example-custom-origin",
"DomainName" => "example.com",
"CustomOriginConfig" => {
"HTTPPort" => "80",
"HTTPSPort" => "443",
"OriginProtocolPolicy" => "match-viewer"
}
}
]
}
}
}
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cloudfront/helpers/origins.rb', line 57 def self.from_hash(hash) hash = hash["Origins"] || hash self.new do unless hash["Items"].nil? origins_list = hash["Items"]["Origin"].is_a?(Hash) ? [hash["Items"]["Origin"]] : hash["Items"]["Origin"] for origin_hash in origins_list unless origin_hash.nil? self.origins.push(Origin.from_hash(origin_hash)) end end end end end |
Instance Method Details
#build_xml(xml) ⇒ Object
<Origins>
<Quantity>number of origins</Quantity>
<Items>
... see Origin class
</Items>
</Origins>
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cloudfront/helpers/origins.rb', line 78 def build_xml(xml) check_configuration xml.Origins { xml.Quantity @origins.size if @origins.size > 0 xml.Items { for origin in @origins origin.build_xml(xml) end } end } end |
#validate ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cloudfront/helpers/origins.rb', line 21 def validate # put origin in a list (this is done for single origin distributions) @origins = [@origins] unless @origins.is_a? Array for origin in @origins if origin.is_a?(Origin) origin.check_configuration end end end |