Sha256: 3e3196ae7585f28a010540d50a7d014542003016dcdb92436b4ea9b16884c05f

Contents?: true

Size: 1.89 KB

Versions: 206

Compression:

Stored size: 1.89 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['endpoints'].key?(region_name)
        end

      end
    end
  end
end

Version data entries

206 entries across 206 versions & 2 rubygems

Version Path
aws-sdk-core-2.10.53 lib/aws-sdk-core/partitions/region.rb
aws-partitions-1.23.0 lib/aws-partitions/region.rb
aws-sdk-core-2.10.52 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.51 lib/aws-sdk-core/partitions/region.rb
aws-partitions-1.22.0 lib/aws-partitions/region.rb
aws-sdk-core-2.10.50 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.49 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.48 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.47 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.46 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.45 lib/aws-sdk-core/partitions/region.rb
aws-partitions-1.21.0 lib/aws-partitions/region.rb
aws-sdk-core-2.10.44 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.43 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.42 lib/aws-sdk-core/partitions/region.rb
aws-partitions-1.20.0 lib/aws-partitions/region.rb
aws-sdk-core-2.10.41 lib/aws-sdk-core/partitions/region.rb
aws-sdk-core-2.10.40 lib/aws-sdk-core/partitions/region.rb
aws-partitions-1.19.0 lib/aws-partitions/region.rb
aws-sdk-core-2.10.39 lib/aws-sdk-core/partitions/region.rb