Sha256: dcfe2efac814a65185ba7f8d0410c004c11d88af27d25306f18dbc5a541e1cea

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

require 'fog/core/collection'
require 'fog/dns/models/dynect/record'

module Fog
  module DNS
    class Dynect

      class Records < Fog::Collection

        attribute :zone

        model Fog::DNS::Dynect::Record

        def all
          requires :zone
          data = []
          connection.get_node_list(zone.domain).body['data'].each do |fqdn|
            records = connection.get_record('ANY', zone.domain, fqdn).body['data']

            # data in format ['/REST/xRecord/domain/fqdn/identity]
            records.map! do |record|
              tokens = record.split('/')
              {
                :identity => tokens.last,
                :fqdn     => fqdn,
                :type     => tokens[2][0...-6] # everything before 'Record'
              }
            end

            data.concat(records)
          end

          # leave out the default, read only records
          data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])}

          load(data)
        end

        def get(record_id)
          # FIXME: can this be done more efficiently?
          all.detect {|record| record.identity == record_id}
        end

        def new(attributes = {})
          requires :zone
          super({ :zone => zone }.merge!(attributes))
        end

      end

    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
brightbox-cli-0.13.1 lib/brightbox-cli/vendor/fog/lib/fog/dns/models/dynect/records.rb
brightbox-cli-0.13.0 lib/brightbox-cli/vendor/fog/lib/fog/dns/models/dynect/records.rb
fog-0.11.0 lib/fog/dns/models/dynect/records.rb