Sha256: 217c0dbcf3555491f94d3d85d31bc56209c42738cbae3938d3ece55a63d813bb

Contents?: true

Size: 1.3 KB

Versions: 51

Compression:

Stored size: 1.3 KB

Contents

require 'aws-sdk'
require 'contracts'
require_relative 'service'

module Cloudstrap
  module Amazon
    class Route53 < Service
      include ::Contracts::Core
      include ::Contracts::Builtin

      Contract None => ArrayOf[::Aws::Route53::Types::HostedZone]
      def zones
        @zones ||= zones!
      end

      Contract None => ArrayOf[::Aws::Route53::Types::HostedZone]
      def zones!
        @zones = call_api(:list_hosted_zones).hosted_zones
      end

      Contract String => Maybe[::Aws::Route53::Types::HostedZone]
      def zone(name)
        name = name.end_with?('.') ? name : name.dup.concat('.')

        zones.find { |zone| zone.name == name }
      end

      Contract String => ArrayOf[String]
      def zone_names
        @zone_names ||= zones.map(&:name)
      end

      Contract String => Maybe[String]
      def longest_matching_suffix(name)
        fragments = name.split '.'
        fragments
          .each_with_index
          .map { |_, i| fragments.drop(i).join('.') + '.' }
          .find { |fragment| zone_names.include? fragment }
      end

      Contract String => Maybe[String]
      def zone_id(name)
        return unless zone = zone(name)

        zone(name).id.split('/').last
      end

      private

      def client
        ::Aws::Route53::Client
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
cloudstrap-0.51.1.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.50.1.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.12.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.11.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.10.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.8.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.4.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.2.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.1.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.49.0.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.48.15.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.48.2.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.48.0.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.47.8.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.47.7.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.47.2.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.47.0.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.46.7.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.46.4.pre lib/cloudstrap/amazon/route53.rb
cloudstrap-0.46.3.pre lib/cloudstrap/amazon/route53.rb