class Cumulus::S3::WebsiteConfig

Attributes

error[R]
index[R]
redirect[R]

Public Class Methods

new(json = nil) click to toggle source

Public: Constructor

json - a hash representing the JSON configuration, expects to be handed

the 'website' node of S3 configuration.
# File lib/s3/models/WebsiteConfig.rb, line 12
def initialize(json = nil)
  if json
    @redirect = json["redirect"]
    @index = json["index"]
    @error = json["error"]
  end
end

Public Instance Methods

!=(other) click to toggle source

Public: Check if this WebsiteConfig is not equal to the other object

other - the other object to check

Returns whether this WebsiteConfig is not equal to `other`

# File lib/s3/models/WebsiteConfig.rb, line 90
def !=(other)
  !(self == other)
end
==(other) click to toggle source

Public: Check WebsiteConfig equality with other objects

other - the other object to check

Returns whether this WebsiteConfig is equal to `other`

# File lib/s3/models/WebsiteConfig.rb, line 74
def ==(other)
  if !other.is_a? WebsiteConfig or
      @redirect != other.redirect or
      @index != other.index or
      @error != other.error
    false
  else
    true
  end
end
populate!(aws) click to toggle source

Public: Populate this WebsiteConfig with the values in an AWS WebsiteConfiguration object.

aws - the aws object to populate from

# File lib/s3/models/WebsiteConfig.rb, line 24
def populate!(aws)
  @index = aws.safe_index
  @error = aws.safe_error
  @redirect = aws.safe_redirection
end
to_aws() click to toggle source

Public: Produce a hash that is compatible with AWS website configuration.

Returns the website configuration in AWS format

# File lib/s3/models/WebsiteConfig.rb, line 33
def to_aws
  if @index
    {
      error_document: {
        key: @error
      },
      index_document: {
        suffix: @index
      },
    }
  else
    {
      redirect_all_requests_to: {
        host_name: if @redirect and @redirect.include?("://")
            @redirect.split("://")[1]
          else
            @redirect
          end,
        protocol: if @redirect and @redirect.include?("://") then @redirect.split("://")[0] end
      }
    }
  end
end
to_h() click to toggle source

Public: Converts this WebsiteConfig to a hash that matches Cumulus configuration.

Returns the hash

# File lib/s3/models/WebsiteConfig.rb, line 61
def to_h
  {
    error: @error,
    index: @index,
    redirect: @redirect,
  }.reject { |k, v| v.nil? }
end
to_s() click to toggle source
# File lib/s3/models/WebsiteConfig.rb, line 94
def to_s
  if @redirect
    "Redirect all traffic to #{@redirect}"
  elsif @index
    if @error
      "Index document: #{@index}, Error document: #{@error}"
    else
      "Index document: #{@index}"
    end
  end
end