Class: Cloudfront::Helpers::Aliases
- Inherits:
-
Object
- Object
- Cloudfront::Helpers::Aliases
- Includes:
- Utils::ConfigurationChecker, Utils::XmlSerializer
- Defined in:
- lib/cloudfront/helpers/aliases.rb
Instance Attribute Summary collapse
-
#cnames ⇒ Object
Returns the value of attribute cnames.
Attributes included from Utils::ConfigurationChecker
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
A factory method that creates a Aliases instance from a hash Input example hash = { “Aliases” => { “Quantity” => “number of CNAME cnames”, “Items” => { “CNAME” => “CNAME alias” } } }.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
Output example <Aliases> <Quantity>number of CNAME cnames</Quantity> <Items> <CNAME>CNAME alias</CNAME> </Items> </Aliases>.
-
#initialize(&block) ⇒ Aliases
constructor
A new instance of Aliases.
- #validate ⇒ Object
Methods included from Utils::XmlSerializer
Methods included from Utils::ConfigurationChecker
Constructor Details
#initialize(&block) ⇒ Aliases
Returns a new instance of Aliases.
11 12 13 14 15 16 17 |
# File 'lib/cloudfront/helpers/aliases.rb', line 11 def initialize(&block) #set default values @cnames = [] #set values from block instance_eval &block if block_given? end |
Instance Attribute Details
#cnames ⇒ Object
Returns the value of attribute cnames.
9 10 11 |
# File 'lib/cloudfront/helpers/aliases.rb', line 9 def cnames @cnames end |
Class Method Details
.from_hash(hash) ⇒ Object
A factory method that creates a Aliases instance from a hash Input example hash = {
"Aliases" => {
"Quantity" => "number of CNAME cnames",
"Items" => {
"CNAME" => "CNAME alias"
}
}
}
41 42 43 44 45 46 |
# File 'lib/cloudfront/helpers/aliases.rb', line 41 def self.from_hash(hash) hash = hash["Aliases"] || hash self.new do self.cnames = Array.wrap((hash["Items"] || {})["CNAME"]) end end |
Instance Method Details
#build_xml(xml) ⇒ Object
Output example <Aliases>
<Quantity>number of CNAME cnames</Quantity>
<Items>
<CNAME>CNAME alias</CNAME>
</Items>
</Aliases>
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cloudfront/helpers/aliases.rb', line 55 def build_xml(xml) check_configuration xml.Aliases { xml.Quantity @cnames.size if @cnames.size > 0 xml.Items { for cname in Array.wrap @cnames xml.CNAME cname end } end } end |
#validate ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cloudfront/helpers/aliases.rb', line 19 def validate # some wrapping @cnames = Array.wrap @cnames # wraps single elements into an array and removes nil parasites # Some additional checking should be done on cnames. for cname in cnames .push("#{cname} isn't a valid url") unless cname =~ Cloudfront::Utils::Util::URL_REGEXP end end |