Class: LaunchDarkly::Interfaces::DataSystem::ChangeSetBuilder
- Inherits:
-
Object
- Object
- LaunchDarkly::Interfaces::DataSystem::ChangeSetBuilder
- Defined in:
- lib/ldclient-rb/interfaces/data_system.rb
Overview
ChangeSetBuilder is a helper for constructing a ChangeSet.
This type is not stable, and not subject to any backwards compatibility guarantees or semantic versioning. It is in early access. If you want access to this feature please join the EAP. launchdarkly.com/docs/sdk/features/data-saving-mode
Instance Attribute Summary collapse
-
#changes ⇒ Array<Change>
The changes.
-
#intent ⇒ String?
The current intent (IntentCode).
Class Method Summary collapse
-
.empty(selector) ⇒ ChangeSet
Returns an empty ChangeSet, useful for initializing without data.
-
.no_changes ⇒ ChangeSet
Represents an intent that the current data is up-to-date and doesn’t require changes.
Instance Method Summary collapse
-
#add_delete(kind, key, version) ⇒ void
Adds a deletion to the changeset.
-
#add_put(kind, key, version, obj) ⇒ void
Adds a new object to the changeset.
-
#expect_changes ⇒ void
Ensures that the current ChangeSetBuilder is prepared to handle changes.
-
#finish(selector) ⇒ ChangeSet
Identifies a changeset with a selector and returns the completed changeset.
-
#initialize ⇒ ChangeSetBuilder
constructor
A new instance of ChangeSetBuilder.
-
#reset ⇒ void
Clears any existing changes while preserving the current intent.
-
#start(intent) ⇒ void
Begins a new change set with a given intent.
Constructor Details
#initialize ⇒ ChangeSetBuilder
Returns a new instance of ChangeSetBuilder.
418 419 420 421 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 418 def initialize @intent = nil @changes = [] end |
Instance Attribute Details
#changes ⇒ Array<Change>
Returns The changes.
416 417 418 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 416 def changes @changes end |
#intent ⇒ String?
Returns The current intent (IntentCode).
413 414 415 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 413 def intent @intent end |
Class Method Details
.empty(selector) ⇒ ChangeSet
Returns an empty ChangeSet, useful for initializing without data.
442 443 444 445 446 447 448 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 442 def self.empty(selector) ChangeSet.new( intent_code: IntentCode::TRANSFER_FULL, selector: selector, changes: [] ) end |
.no_changes ⇒ ChangeSet
Represents an intent that the current data is up-to-date and doesn’t require changes.
428 429 430 431 432 433 434 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 428 def self.no_changes ChangeSet.new( intent_code: IntentCode::TRANSFER_NONE, selector: Selector.no_selector, changes: [] ) end |
Instance Method Details
#add_delete(kind, key, version) ⇒ void
This method returns an undefined value.
Adds a deletion to the changeset.
536 537 538 539 540 541 542 543 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 536 def add_delete(kind, key, version) @changes << Change.new( action: ChangeType::DELETE, kind: kind, key: key, version: version ) end |
#add_put(kind, key, version, obj) ⇒ void
This method returns an undefined value.
Adds a new object to the changeset.
518 519 520 521 522 523 524 525 526 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 518 def add_put(kind, key, version, obj) @changes << Change.new( action: ChangeType::PUT, kind: kind, key: key, version: version, object: obj ) end |
#expect_changes ⇒ void
This method returns an undefined value.
Ensures that the current ChangeSetBuilder is prepared to handle changes.
467 468 469 470 471 472 473 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 467 def expect_changes raise "changeset: cannot expect changes without a server-intent" if @intent.nil? return unless @intent == IntentCode::TRANSFER_NONE @intent = IntentCode::TRANSFER_CHANGES end |
#finish(selector) ⇒ ChangeSet
Identifies a changeset with a selector and returns the completed changeset.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 491 def finish(selector) raise "changeset: cannot complete without a server-intent" if @intent.nil? changeset = ChangeSet.new( intent_code: @intent, selector: selector, changes: @changes ) @changes = [] # Once a full transfer has been processed, all future changes should be # assumed to be changes. Flag delivery can override this behavior by # sending a new server intent to any connected stream. @intent = IntentCode::TRANSFER_CHANGES if @intent == IntentCode::TRANSFER_FULL changeset end |
#reset ⇒ void
This method returns an undefined value.
Clears any existing changes while preserving the current intent.
480 481 482 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 480 def reset @changes = [] end |
#start(intent) ⇒ void
This method returns an undefined value.
Begins a new change set with a given intent.
456 457 458 459 |
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 456 def start(intent) @intent = intent @changes = [] end |