Class: RecordStore::Changeset

Inherits:
Object
  • Object
show all
Defined in:
lib/record_store/changeset.rb

Defined Under Namespace

Classes: Change

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_records: [], desired_records: [], provider:, zone:) ⇒ Changeset



49
50
51
52
53
54
55
56
57
58
# File 'lib/record_store/changeset.rb', line 49

def initialize(current_records: [], desired_records: [], provider:, zone:)
  @current_records = Set.new(current_records)
  @desired_records = Set.new(desired_records)
  @provider = provider
  @zone = zone

  @additions, @removals, @updates = [], [], []

  build_changeset
end

Instance Attribute Details

#additionsObject (readonly)

Returns the value of attribute additions.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def additions
  @additions
end

#current_recordsObject (readonly)

Returns the value of attribute current_records.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def current_records
  @current_records
end

#desired_recordsObject (readonly)

Returns the value of attribute desired_records.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def desired_records
  @desired_records
end

#providerObject (readonly)

Returns the value of attribute provider.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def provider
  @provider
end

#removalsObject (readonly)

Returns the value of attribute removals.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def removals
  @removals
end

#updatesObject (readonly)

Returns the value of attribute updates.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def updates
  @updates
end

#zoneObject (readonly)

Returns the value of attribute zone.



36
37
38
# File 'lib/record_store/changeset.rb', line 36

def zone
  @zone
end

Class Method Details

.build_from(provider:, zone:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/record_store/changeset.rb', line 38

def self.build_from(provider:, zone:)
  current_zone = provider.build_zone(zone_name: zone.unrooted_name, config: zone.config)

  self.new(
    current_records: current_zone.records,
    desired_records: zone.records,
    provider: provider,
    zone: zone.unrooted_name
  )
end

Instance Method Details

#applyObject



60
61
62
# File 'lib/record_store/changeset.rb', line 60

def apply
  provider.apply_changeset(self)
end

#changesObject



68
69
70
# File 'lib/record_store/changeset.rb', line 68

def changes
  updates.to_a + removals.to_a + additions.to_a
end

#empty?Boolean



72
73
74
# File 'lib/record_store/changeset.rb', line 72

def empty?
  changes.empty?
end

#unchangedObject



64
65
66
# File 'lib/record_store/changeset.rb', line 64

def unchanged
  current_records & desired_records
end