Sha256: df714cc50c35ff38e729ca9eca8ec5eb1c9485760b2264eb74913cfaee38bd1e

Contents?: true

Size: 1.92 KB

Versions: 991

Compression:

Stored size: 1.92 KB

Contents

require 'set'

module Aws
  module Partitions
    class Region

      # @option options [required, String] :name
      # @option options [required, String] :description
      # @option options [required, String] :partition_name
      # @option options [required, Set<String>] :services
      # @api private
      def initialize(options = {})
        @name = options[:name]
        @description = options[:description]
        @partition_name = options[:partition_name]
        @services = options[:services]
      end

      # @return [String] The name of this region, e.g. "us-east-1".
      attr_reader :name

      # @return [String] A short description of this region.
      attr_reader :description

      # @return [String] The partition this region exists in, e.g. "aws",
      #   "aws-cn", "aws-us-gov".
      attr_reader :partition_name

      # @return [Set<String>] The list of services available in this region.
      #   Service names are the module names as used by the AWS SDK
      #   for Ruby.
      attr_reader :services

      class << self

        # @api private
        def build(region_name, region, partition)
          Region.new(
            name: region_name,
            description: region['description'],
            partition_name: partition['partition'],
            services: region_services(region_name, partition)
          )
        end

        private

        def region_services(region_name, partition)
          Partitions.service_ids.inject(Set.new) do |services, (svc_name, svc_id)|
            if svc = partition['services'][svc_id]
              services << svc_name if service_in_region?(svc, region_name)
            else
              #raise "missing endpoints for #{svc_name} / #{svc_id}"
            end
            services
          end
        end

        def service_in_region?(svc, region_name)
          svc.key?('endpoints') && svc['endpoints'].key?(region_name)
        end

      end
    end
  end
end

Version data entries

991 entries across 991 versions & 2 rubygems

Version Path
aws-sdk-core-2.11.572 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.571 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.570 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.569 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.568 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.567 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.566 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.565 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.564 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.563 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.562 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.561 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.560 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.559 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.558 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.557 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.556 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.555 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.554 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.11.553 lib/aws-sdk-core/partitions/region.rb