Class: RecordStore::Changeset
- Inherits:
-
Object
- Object
- RecordStore::Changeset
- Defined in:
- lib/record_store/changeset.rb
Defined Under Namespace
Classes: Change
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#current_records ⇒ Object
readonly
Returns the value of attribute current_records.
-
#desired_records ⇒ Object
readonly
Returns the value of attribute desired_records.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#removals ⇒ Object
readonly
Returns the value of attribute removals.
-
#updates ⇒ Object
readonly
Returns the value of attribute updates.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Class Method Summary collapse
Instance Method Summary collapse
- #apply ⇒ Object
- #changes ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(current_records: [], desired_records: [], provider:, zone:) ⇒ Changeset
constructor
A new instance of Changeset.
- #unchanged ⇒ Object
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
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
36 37 38 |
# File 'lib/record_store/changeset.rb', line 36 def additions @additions end |
#current_records ⇒ Object (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_records ⇒ Object (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 |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
36 37 38 |
# File 'lib/record_store/changeset.rb', line 36 def provider @provider end |
#removals ⇒ Object (readonly)
Returns the value of attribute removals.
36 37 38 |
# File 'lib/record_store/changeset.rb', line 36 def removals @removals end |
#updates ⇒ Object (readonly)
Returns the value of attribute updates.
36 37 38 |
# File 'lib/record_store/changeset.rb', line 36 def updates @updates end |
#zone ⇒ Object (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
#apply ⇒ Object
60 61 62 |
# File 'lib/record_store/changeset.rb', line 60 def apply provider.apply_changeset(self) end |
#changes ⇒ Object
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 |
#unchanged ⇒ Object
64 65 66 |
# File 'lib/record_store/changeset.rb', line 64 def unchanged current_records & desired_records end |