class Flipper::Adapters::Sync

TODO: Syncing should happen in a background thread on a regular interval rather than in the main thread only when reads happen.

Attributes

name[R]

Public: The name of the adapter.

synchronizer[R]

Public: The synchronizer that will keep the local and remote in sync.

Public Class Methods

new(local, remote, options = {}) click to toggle source

Public: Build a new sync instance.

local - The local flipper adapter that should serve reads. remote - The remote flipper adpater that should serve writes and update

the local on an interval.

interval - The number of milliseconds between syncs from remote to

local. Default value is set in IntervalSynchronizer.
# File lib/flipper/adapters/sync.rb, line 25
def initialize(local, remote, options = {})
  @name = :sync
  @local = local
  @remote = remote
  @synchronizer = options.fetch(:synchronizer) do
    instrumenter = options[:instrumenter]
    sync_options = {}
    sync_options[:instrumenter] = instrumenter if instrumenter
    synchronizer = Synchronizer.new(@local, @remote, sync_options)
    IntervalSynchronizer.new(synchronizer, interval: options[:interval])
  end
  sync
end

Public Instance Methods

add(feature) click to toggle source
# File lib/flipper/adapters/sync.rb, line 59
def add(feature)
  result = @remote.add(feature)
  @local.add(feature)
  result
end
clear(feature) click to toggle source
# File lib/flipper/adapters/sync.rb, line 71
def clear(feature)
  result = @remote.clear(feature)
  @local.clear(feature)
  result
end
disable(feature, gate, thing) click to toggle source
# File lib/flipper/adapters/sync.rb, line 83
def disable(feature, gate, thing)
  result = @remote.disable(feature, gate, thing)
  @local.disable(feature, gate, thing)
  result
end
enable(feature, gate, thing) click to toggle source
# File lib/flipper/adapters/sync.rb, line 77
def enable(feature, gate, thing)
  result = @remote.enable(feature, gate, thing)
  @local.enable(feature, gate, thing)
  result
end
features() click to toggle source
# File lib/flipper/adapters/sync.rb, line 39
def features
  sync
  @local.features
end
get(feature) click to toggle source
# File lib/flipper/adapters/sync.rb, line 44
def get(feature)
  sync
  @local.get(feature)
end
get_all() click to toggle source
# File lib/flipper/adapters/sync.rb, line 54
def get_all
  sync
  @local.get_all
end
get_multi(features) click to toggle source
# File lib/flipper/adapters/sync.rb, line 49
def get_multi(features)
  sync
  @local.get_multi(features)
end
remove(feature) click to toggle source
# File lib/flipper/adapters/sync.rb, line 65
def remove(feature)
  result = @remote.remove(feature)
  @local.remove(feature)
  result
end

Private Instance Methods

sync() click to toggle source
# File lib/flipper/adapters/sync.rb, line 91
def sync
  @synchronizer.call
end