class Aws::Partitions::Partition

Attributes

name[R]

@return [String] The partition name, e.g. “aws”, “aws-cn”, “aws-us-gov”.

Public Class Methods

build(partition) click to toggle source

@api private

# File lib/aws-partitions/partition.rb, line 69
def build(partition)
  Partition.new(
    name: partition['partition'],
    regions: build_regions(partition),
    services: build_services(partition)
  )
end
new(options = {}) click to toggle source

@option options [required, String] :name @option options [required, Hash<String,Region>] :regions @option options [required, Hash<String,Service>] :services @api private

# File lib/aws-partitions/partition.rb, line 10
def initialize(options = {})
  @name = options[:name]
  @regions = options[:regions]
  @services = options[:services]
end

Private Class Methods

build_regions(partition) click to toggle source

@param [Hash] partition @return [Hash<String,Region>]

# File lib/aws-partitions/partition.rb, line 81
def build_regions(partition)
  partition['regions'].each_with_object({}) do
    |(region_name, region), regions|
    next if region_name == "#{partition['partition']}-global"

    regions[region_name] = Region.build(
      region_name, region, partition
    )
  end
end
build_services(partition) click to toggle source

@param [Hash] partition @return [Hash<String,Service>]

# File lib/aws-partitions/partition.rb, line 94
def build_services(partition)
  Partitions.service_ids.each_with_object({}) do
    |(service_name, service), services|
    service_data = partition['services'].fetch(
      service, 'endpoints' => {}
    )
    services[service_name] = Service.build(
      service_name, service_data, partition
    )
  end
end

Public Instance Methods

region(region_name) click to toggle source

@param [String] region_name The name of the region, e.g. “us-east-1”. @return [Region] @raise [ArgumentError] Raises `ArgumentError` for unknown region name.

# File lib/aws-partitions/partition.rb, line 22
def region(region_name)
  if @regions.key?(region_name)
    @regions[region_name]
  else
    msg = "invalid region name #{region_name.inspect}; valid region "\
          "names include #{@regions.keys.join(', ')}"
    raise ArgumentError, msg
  end
end
region?(region_name) click to toggle source

@param [String] region_name The name of the region, e.g. “us-east-1”. @return [Boolean] true if the region is in the partition.

# File lib/aws-partitions/partition.rb, line 39
def region?(region_name)
  @regions.key?(region_name)
end
regions() click to toggle source

@return [Array<Region>]

# File lib/aws-partitions/partition.rb, line 33
def regions
  @regions.values
end
service(service_name) click to toggle source

@param [String] service_name The service module name. @return [Service] @raise [ArgumentError] Raises `ArgumentError` for unknown service name.

# File lib/aws-partitions/partition.rb, line 46
def service(service_name)
  if @services.key?(service_name)
    @services[service_name]
  else
    msg = "invalid service name #{service_name.inspect}; valid service "\
          "names include #{@services.keys.join(', ')}"
    raise ArgumentError, msg
  end
end
service?(service_name) click to toggle source

@param [String] service_name The service module name. @return [Boolean] true if the service is in the partition.

# File lib/aws-partitions/partition.rb, line 63
def service?(service_name)
  @services.key?(service_name)
end
services() click to toggle source

@return [Array<Service>]

# File lib/aws-partitions/partition.rb, line 57
def services
  @services.values
end