Class: Roadworker::Route53Wrapper::ResourceRecordSetCollectionWrapper

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/roadworker/route53-wrapper.rb

Overview

HostedZoneWrapper

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initialize(resource_record_sets, hosted_zone, options) ⇒ ResourceRecordSetCollectionWrapper

Returns a new instance of ResourceRecordSetCollectionWrapper.



105
106
107
108
109
# File 'lib/roadworker/route53-wrapper.rb', line 105

def initialize(resource_record_sets, hosted_zone, options)
  @resource_record_sets = resource_record_sets
  @hosted_zone = hosted_zone
  @options = options
end

Instance Method Details

#create(name, type, expected_record) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/roadworker/route53-wrapper.rb', line 117

def create(name, type, expected_record)
  log(:info, 'Create ResourceRecordSet', :cyan) do
    log_id = [name, type].join(' ')
    rrset_setid = expected_record.set_identifier
    rrset_setid ? (log_id + " (#{rrset_setid})") : log_id
  end

  if @options.dry_run
    record = expected_record
  else
    opts = {}

    Route53Wrapper::RRSET_ATTRS.each do |attribute|
      value = expected_record.send(attribute)
      next unless value

      case attribute
      when :dns_name
        attribute = :alias_target
        dns_name, dns_name_opts = value
        value = AWS::Route53.dns_name_to_alias_target(dns_name, dns_name_opts, @hosted_zone.id, @hosted_zone.name || @options.hosted_zone_name)
      when :health_check
        attribute = :health_check_id
        value = @options.health_checks.find_or_create(value)
      end

      opts[attribute] = value
    end

    record = @resource_record_sets.create(name, type, opts)
    @options.updated = true
  end

  ResourceRecordSetWrapper.new(record, @hosted_zone, @options)
end

#eachObject



111
112
113
114
115
# File 'lib/roadworker/route53-wrapper.rb', line 111

def each
  Collection.batch(@resource_record_sets) do |record|
    yield(ResourceRecordSetWrapper.new(record, @hosted_zone, @options))
  end
end