Sha256: ff78280c280f672dd87a75edae712c98879b449d1d6cf2ddf3a0ba999e1c6505

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

module Glare
  class CfDnsRecord
    def initialize(id:, name:, type:, content:)
      @id = id
      @name = name
      @type = type
      @content = content
    end
    attr_reader :id, :name, :type, :content
  end

  class CfDnsRecords
    class << self
      def from_result(api_result)
        response = ApiResponse.new(api_result)
        result = response.result

        records = result.map do |item|
          CfDnsRecord.new(
            id: item['id'],
            name: item['name'],
            type: item['type'],
            content: item['content']
          )
        end

        new(records)
      end

      def empty
        new([])
      end
    end

    def initialize(records)
      @records = records
    end

    def to_update(desired_records)
      @records.reject do |record|
        desired_records.any? { |r| r.content == record.content }
      end
    end

    def count
      @records.count
    end

    def contents
      @records.map(&:content)
    end

    def each
      @records.each { |record| yield(record) }
    end

    def to_delete(target_number)
      records_to_delete = count - target_number
      return CfDnsRecords.empty if records_to_delete < 0

      @records.last(records_to_delete)
    end

    def to_create(desired_records)
      desired_records.drop(count)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glare-0.3.0 lib/glare/cf_dns_records.rb
glare-0.1.2 lib/glare/cf_dns_records.rb