Class: Clouddns::ZoneMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/clouddns/zone_migration.rb

Defined Under Namespace

Modules: Change

Instance Method Summary collapse

Constructor Details

#initialize(zone, fog_zone) ⇒ ZoneMigration

Returns a new instance of ZoneMigration.



26
27
28
29
30
# File 'lib/clouddns/zone_migration.rb', line 26

def initialize zone, fog_zone
  @zone = zone
  @fog_zone = fog_zone
  @changes = nil
end

Instance Method Details

#changesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/clouddns/zone_migration.rb', line 31

def changes
  return @changes if @changes
  @changes = []
  fog_records = Hash[@fog_zone.records.map {|r| [[fog_record_name(r), r.type], r] } ]
  @zone.records.each do |record|
    if (fog_record = fog_records.delete([record.name, record.type]))
      if records_equal?(record, fog_record)
        @changes << Change::None.new(record)
      else
        @changes << Change::Remove.new(fog_record)
        @changes << Change::Create.new(record)
      end
    else
      @changes << Change::Create.new(record)
    end
  end

  fog_records.each do |name, record|
    @changes << Change::Remove.new(record)
  end
  @changes
end

#completed?Boolean

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/clouddns/zone_migration.rb', line 60

def completed?
  changes.all? do |change|
    change.class == Change::None
  end
end

#perform!Object



54
55
56
57
58
# File 'lib/clouddns/zone_migration.rb', line 54

def perform!
  changes.each do |change|
    change.perform! @fog_zone
  end
end