Class: LaunchDarkly::Interfaces::DataSystem::ChangeSetBuilder

Inherits:
Object
  • Object
show all
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 not suitable for production usage.

Do not use it. You have been warned.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChangeSetBuilder

Returns a new instance of ChangeSetBuilder.



454
455
456
457
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 454

def initialize
  @intent = nil
  @changes = []
end

Instance Attribute Details

#changesArray<Change>

Returns The changes.

Returns:

  • (Array<Change>)

    The changes



452
453
454
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 452

def changes
  @changes
end

#intentString?

Returns The current intent (IntentCode).

Returns:

  • (String, nil)

    The current intent (IntentCode)



449
450
451
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 449

def intent
  @intent
end

Class Method Details

.empty(selector) ⇒ ChangeSet

Returns an empty ChangeSet, useful for initializing without data.

Parameters:

Returns:



478
479
480
481
482
483
484
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 478

def self.empty(selector)
  ChangeSet.new(
    intent_code: IntentCode::TRANSFER_FULL,
    selector: selector,
    changes: []
  )
end

.no_changesChangeSet

Represents an intent that the current data is up-to-date and doesn't require changes.

Returns:



464
465
466
467
468
469
470
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 464

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.

Parameters:

  • kind (String)

    The object kind (ObjectKind)

  • key (String)

    The key

  • version (Integer)

    The version



572
573
574
575
576
577
578
579
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 572

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.

Parameters:

  • kind (String)

    The object kind (ObjectKind)

  • key (String)

    The key

  • version (Integer)

    The version

  • obj (Hash)

    The object data



554
555
556
557
558
559
560
561
562
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 554

def add_put(kind, key, version, obj)
  @changes << Change.new(
    action: ChangeType::PUT,
    kind: kind,
    key: key,
    version: version,
    object: obj
  )
end

#expect_changesvoid

This method returns an undefined value.

Ensures that the current ChangeSetBuilder is prepared to handle changes.

Raises:

  • (RuntimeError)

    if no server-intent has been set



503
504
505
506
507
508
509
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 503

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.

Parameters:

Returns:

Raises:

  • (RuntimeError)

    if no server-intent has been set



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 527

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

#resetvoid

This method returns an undefined value.

Clears any existing changes while preserving the current intent.



516
517
518
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 516

def reset
  @changes = []
end

#start(intent) ⇒ void

This method returns an undefined value.

Begins a new change set with a given intent.

Parameters:

  • intent (String)

    The intent code (IntentCode)



492
493
494
495
# File 'lib/ldclient-rb/interfaces/data_system.rb', line 492

def start(intent)
  @intent = intent
  @changes = []
end