Class: Cloudfront::Helpers::Logging

Inherits:
Object
  • Object
show all
Includes:
Utils::ConfigurationChecker, Utils::XmlSerializer
Defined in:
lib/cloudfront/helpers/logging.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) ⇒ 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

#bucketObject

Returns the value of attribute bucket.



9
10
11
# File 'lib/cloudfront/helpers/logging.rb', line 9

def bucket
  @bucket
end

#enabledObject

Returns the value of attribute enabled.



9
10
11
# File 'lib/cloudfront/helpers/logging.rb', line 9

def enabled
  @enabled
end

#include_cookiesObject

Returns the value of attribute include_cookies.



9
10
11
# File 'lib/cloudfront/helpers/logging.rb', line 9

def include_cookies
  @include_cookies
end

#prefixObject

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.include_cookies = 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

#validateObject



22
23
24
25
26
# File 'lib/cloudfront/helpers/logging.rb', line 22

def validate
  error_messages.push "enabled should be a boolean" unless !!@enabled == @enabled
  error_messages.push "include_cookies should be a boolean or 'undefined'" unless !!@include_cookies == @include_cookies || @include_cookies == "undefined"
  error_messages.push "You must specify a bucket" if @enabled && @bucket.nil?
end