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.



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

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



115
116
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
# File 'lib/roadworker/route53-wrapper.rb', line 115

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 |attr|
      value = expected_record.send(attr)
      next unless value

      case attr
      when :dns_name
        attr = :alias_target
        value = @options.route53.dns_name_to_alias_target(value)
      when :health_check
        attr = :health_check_id
        value = @options.health_checks.find_or_create(value)
      end

      opts[attr] = value
    end

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

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

#eachObject



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

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