Sha256: f69e3bfc8df25b5f76ac740372ee834b123e06b4f19cb437717284e7eec108b8

Contents?: true

Size: 1.95 KB

Versions: 672

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

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

672 entries across 672 versions & 1 rubygems

Version Path
aws-partitions-1.1012.0 lib/aws-partitions/region.rb
aws-partitions-1.1011.0 lib/aws-partitions/region.rb
aws-partitions-1.1010.0 lib/aws-partitions/region.rb
aws-partitions-1.1009.0 lib/aws-partitions/region.rb
aws-partitions-1.1008.0 lib/aws-partitions/region.rb
aws-partitions-1.1007.0 lib/aws-partitions/region.rb
aws-partitions-1.1006.0 lib/aws-partitions/region.rb
aws-partitions-1.1005.0 lib/aws-partitions/region.rb
aws-partitions-1.1004.0 lib/aws-partitions/region.rb
aws-partitions-1.1003.0 lib/aws-partitions/region.rb
aws-partitions-1.1002.0 lib/aws-partitions/region.rb
aws-partitions-1.1001.0 lib/aws-partitions/region.rb
aws-partitions-1.1000.0 lib/aws-partitions/region.rb
aws-partitions-1.999.0 lib/aws-partitions/region.rb
aws-partitions-1.998.0 lib/aws-partitions/region.rb
aws-partitions-1.997.0 lib/aws-partitions/region.rb
aws-partitions-1.996.0 lib/aws-partitions/region.rb
aws-partitions-1.995.0 lib/aws-partitions/region.rb
aws-partitions-1.994.0 lib/aws-partitions/region.rb
aws-partitions-1.993.0 lib/aws-partitions/region.rb