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
Returns a new instance of Changeset.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/record_store/changeset.rb', line 57 def initialize(current_records: [], desired_records: [], provider:, zone:) @current_records = Set.new(normalize_records(current_records)) @desired_records = Set.new(normalize_records(desired_records)) @provider = provider @zone = zone @additions = [] @removals = [] @updates = [] build_changeset end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def additions @additions end |
#current_records ⇒ Object (readonly)
Returns the value of attribute current_records.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def current_records @current_records end |
#desired_records ⇒ Object (readonly)
Returns the value of attribute desired_records.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def desired_records @desired_records end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def provider @provider end |
#removals ⇒ Object (readonly)
Returns the value of attribute removals.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def removals @removals end |
#updates ⇒ Object (readonly)
Returns the value of attribute updates.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def updates @updates end |
#zone ⇒ Object (readonly)
Returns the value of attribute zone.
39 40 41 |
# File 'lib/record_store/changeset.rb', line 39 def zone @zone end |
Class Method Details
.build_from(provider:, zone:, all: false) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/record_store/changeset.rb', line 42 def build_from(provider:, zone:, all: false) current_zone = provider.build_zone(zone_name: zone.unrooted_name, config: zone.config) current_records = all ? current_zone.all : current_zone.records desired_records = all ? zone.all : zone.records new( current_records: current_records, desired_records: desired_records, provider: provider, zone: zone.unrooted_name, ) end |
Instance Method Details
#apply ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/record_store/changeset.rb', line 70 def apply puts "Applying #{additions.size} additions, #{removals.size} removals, and #{updates.size} updates..." provider.apply_changeset(self) puts "Published #{zone} changes to #{provider}\n\n" end |
#changes ⇒ Object
82 83 84 |
# File 'lib/record_store/changeset.rb', line 82 def changes updates.to_a + removals.to_a + additions.to_a end |
#empty? ⇒ Boolean
86 87 88 |
# File 'lib/record_store/changeset.rb', line 86 def empty? changes.empty? end |
#unchanged ⇒ Object
78 79 80 |
# File 'lib/record_store/changeset.rb', line 78 def unchanged current_records & desired_records end |