Class: Cloudfront::Helpers::OriginAccessIdentity

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

Returns a new instance of OriginAccessIdentity.



12
13
14
15
16
17
18
19
# File 'lib/cloudfront/helpers/origin_access_identity.rb', line 12

def initialize(&block)
  #setting default values
  @caller_reference = Cloudfront::Utils::Util.generate_caller_reference
  @comment = "Created with cloudfront Gem, visit https://github.com/Belkacem/cloudfront"

  #set value from block
  instance_eval &block if block_given?
end

Instance Attribute Details

#caller_referenceObject

Returns the value of attribute caller_reference.



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

def caller_reference
  @caller_reference
end

#commentObject

Returns the value of attribute comment.



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

def comment
  @comment
end

Class Method Details

.from_hash(hash) ⇒ Object

{

"CloudFrontOriginAccessIdentityConfig" => {
    "CallerReference" => "ref",
    "Comment" => "The comment."
}

}



34
35
36
37
38
39
40
# File 'lib/cloudfront/helpers/origin_access_identity.rb', line 34

def self.from_hash(hash)
  hash = hash["CloudFrontOriginAccessIdentityConfig"] || hash
  self.new do
    self.caller_reference = hash["CallerReference"]
    self.comment = hash["Comment"]
  end
end

Instance Method Details

#build_xml(xml) ⇒ Object

<?xml version=“1.0” encoding=“UTF-8”?> <CloudFrontOriginAccessIdentityConfig xmlns=“cloudfront.amazonaws.com/doc/2012-07-01/”>

<CallerReference>ref</CallerReference>
<Comment>The comment.</Comment>

</CloudFrontOriginAccessIdentityConfig>



48
49
50
51
52
53
54
# File 'lib/cloudfront/helpers/origin_access_identity.rb', line 48

def build_xml(xml)
  check_configuration
  xml.CloudFrontOriginAccessIdentityConfig('xmlns' => "http://cloudfront.amazonaws.com/doc/#{Cloudfront::Utils::Api.version}/") {
    xml.CallerReference @caller_reference
    xml.Comment @comment
  }
end

#validateObject



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

def validate
  this = self

  # Error checking
  error_messages.push "The caller_reference shouldn't be empty" if @caller_reference.empty?
end