Class: Cloudfront::Helpers::Logging
- Inherits:
-
Object
- Object
- Cloudfront::Helpers::Logging
- Includes:
- Utils::ConfigurationChecker, Utils::XmlSerializer
- Defined in:
- lib/cloudfront/helpers/logging.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#include_cookies ⇒ Object
Returns the value of attribute include_cookies.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Attributes included from Utils::ConfigurationChecker
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
A factory method that creates a Logging instance from a hash Input example hash = { “Logging” => { “Enabled” => “true | false”, “IncludeCookies” => “true | false”, “Bucket” => “Amazon S3 bucket to save logs in”, “Prefix” => “prefix for log filenames” } }.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
build the xml <Logging> <Enabled>true | false</Enabled> <IncludeCookies>true | false</IncludeCookies> <Bucket>Amazon S3 bucket to save logs in</Bucket> <Prefix>prefix for log filenames</Prefix> </Logging>.
-
#initialize(&block) ⇒ Logging
constructor
A new instance of Logging.
- #validate ⇒ Object
Methods included from Utils::XmlSerializer
Methods included from Utils::ConfigurationChecker
Constructor Details
#initialize(&block) ⇒ Logging
Returns a new instance of Logging.
14 15 16 17 18 19 20 |
# File 'lib/cloudfront/helpers/logging.rb', line 14 def initialize(&block) #set default values @enabled = false @include_cookies = false #set values from block instance_eval &block if block_given? end |
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
9 10 11 |
# File 'lib/cloudfront/helpers/logging.rb', line 9 def bucket @bucket end |
#enabled ⇒ Object
Returns the value of attribute enabled.
9 10 11 |
# File 'lib/cloudfront/helpers/logging.rb', line 9 def enabled @enabled end |
#include_cookies ⇒ Object
Returns the value of attribute include_cookies.
9 10 11 |
# File 'lib/cloudfront/helpers/logging.rb', line 9 def @include_cookies end |
#prefix ⇒ Object
Returns the value of attribute prefix.
9 10 11 |
# File 'lib/cloudfront/helpers/logging.rb', line 9 def prefix @prefix end |
Class Method Details
.from_hash(hash) ⇒ Object
A factory method that creates a Logging instance from a hash Input example hash = {
"Logging" => {
"Enabled" => "true | false",
"IncludeCookies" => "true | false",
"Bucket" => "Amazon S3 bucket to save logs in",
"Prefix" => "prefix for log filenames"
}
}
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cloudfront/helpers/logging.rb', line 38 def self.from_hash(hash) hash = hash["Logging"] || hash self.new do self.enabled = (hash["Enabled"] || "false").to_bool self. = hash["IncludeCookies"].nil? ? "undefined" : hash["IncludeCookies"].to_bool if self.enabled self.bucket = hash["Bucket"] self.prefix = hash["Prefix"] end end end |
Instance Method Details
#build_xml(xml) ⇒ Object
build the xml
<Logging>
<Enabled>true | false</Enabled>
<IncludeCookies>true | false</IncludeCookies>
<Bucket>Amazon S3 bucket to save logs in</Bucket>
<Prefix>prefix for log filenames</Prefix>
</Logging>
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cloudfront/helpers/logging.rb', line 57 def build_xml(xml) check_configuration xml.Logging { xml.Enabled @enabled xml.IncludeCookies @include_cookies unless @include_cookies == "undefined" if @enabled xml.Bucket @bucket xml.Prefix @prefix end } end |
#validate ⇒ Object
22 23 24 25 26 |
# File 'lib/cloudfront/helpers/logging.rb', line 22 def validate .push "enabled should be a boolean" unless !!@enabled == @enabled .push "include_cookies should be a boolean or 'undefined'" unless !!@include_cookies == @include_cookies || @include_cookies == "undefined" .push "You must specify a bucket" if @enabled && @bucket.nil? end |