Sha256: 89af768fb20d4308d6b880a0ae10221d24905d2d8a95a34d27b385d411d96e1a

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

require 'fog/core/model'

module Fog
  module DNS
    class AWS

      class Record < Fog::Model
        extend Fog::Deprecation
        deprecate :ip, :value
        deprecate :ip=, :value=

        identity :name,         :aliases => ['Name']

        attribute :value,       :aliases => ['ResourceRecords']
        attribute :ttl,         :aliases => ['TTL']
        attribute :type,        :aliases => ['Type']
        attribute :status,      :aliases => ['Status']
        attribute :created_at,  :aliases => ['SubmittedAt']

        def initialize(attributes={})
          self.ttl ||= 3600
          super
        end

        def destroy
          options = attributes_to_options('DELETE')
          connection.change_resource_record_sets(zone.id, [options])
          true
        end

        def zone
          @zone
        end

        def save
          options = attributes_to_options('CREATE')
          data = connection.change_resource_record_sets(zone.id, [options]).body
          merge_attributes(data)
          true
        end

        def modify(new_attributes)
          options = []

          # Delete the current attributes
          options << attributes_to_options('DELETE')

          # Create the new attributes
          merge_attributes(new_attributes)
          options << attributes_to_options('CREATE')

          data = connection.change_resource_record_sets(zone.id, options).body
          merge_attributes(data)
          true
        end

        private

        def zone=(new_zone)
          @zone = new_zone
        end

        def attributes_to_options(action)
          requires :name, :ttl, :type, :value, :zone
          {
            :action           => action,
            :name             => name,
            :resource_records => [*value],
            :ttl              => ttl,
            :type             => type
          }
        end

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
brightbox-cli-0.18.1 lib/brightbox-cli/vendor/fog/lib/fog/aws/models/dns/record.rb
brightbox-cli-0.18.0 lib/brightbox-cli/vendor/fog/lib/fog/aws/models/dns/record.rb
brightbox-cli-0.17.5 lib/brightbox-cli/vendor/fog/lib/fog/aws/models/dns/record.rb
ktheory-fog-1.1.2 lib/fog/aws/models/dns/record.rb