class Flipper::Adapters::Sync::FeatureSynchronizer

Internal: Given a feature, local gate values and remote gate values, makes the local equal to the remote.

Public Class Methods

new(feature, local_gate_values, remote_gate_values) click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 28
def initialize(feature, local_gate_values, remote_gate_values)
  @feature = feature
  @local_gate_values = local_gate_values
  @remote_gate_values = remote_gate_values
end

Public Instance Methods

call() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 34
def call
  if remote_disabled?
    return if local_disabled?
    @feature.disable
  elsif remote_boolean_enabled?
    return if local_boolean_enabled?
    @feature.enable
  else
    @feature.disable if local_boolean_enabled?
    sync_actors
    sync_groups
    sync_percentage_of_actors
    sync_percentage_of_time
  end
end

Private Instance Methods

default_config() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 88
def default_config
  @default_config ||= @feature.adapter.default_config
end
default_gate_values() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 92
def default_gate_values
  @default_gate_values ||= GateValues.new(default_config)
end
default_gate_values?(gate_values) click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 96
def default_gate_values?(gate_values)
  gate_values == default_gate_values
end
local_boolean_enabled?() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 108
def local_boolean_enabled?
  local_boolean
end
local_disabled?() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 100
def local_disabled?
  default_gate_values? @local_gate_values
end
remote_boolean_enabled?() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 112
def remote_boolean_enabled?
  remote_boolean
end
remote_disabled?() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 104
def remote_disabled?
  default_gate_values? @remote_gate_values
end
sync_actors() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 52
def sync_actors
  remote_actors_added = remote_actors - local_actors
  remote_actors_added.each do |flipper_id|
    @feature.enable_actor Actor.new(flipper_id)
  end

  remote_actors_removed = local_actors - remote_actors
  remote_actors_removed.each do |flipper_id|
    @feature.disable_actor Actor.new(flipper_id)
  end
end
sync_groups() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 64
def sync_groups
  remote_groups_added = remote_groups - local_groups
  remote_groups_added.each do |group_name|
    @feature.enable_group group_name
  end

  remote_groups_removed = local_groups - remote_groups
  remote_groups_removed.each do |group_name|
    @feature.disable_group group_name
  end
end
sync_percentage_of_actors() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 76
def sync_percentage_of_actors
  return if local_percentage_of_actors == remote_percentage_of_actors

  @feature.enable_percentage_of_actors remote_percentage_of_actors
end
sync_percentage_of_time() click to toggle source
# File lib/flipper/adapters/sync/feature_synchronizer.rb, line 82
def sync_percentage_of_time
  return if local_percentage_of_time == remote_percentage_of_time

  @feature.enable_percentage_of_time remote_percentage_of_time
end