Class: LaunchDarkly::Impl::FlagTracker::FlagValueChangeAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ldclient-rb/impl/flag_tracker.rb

Overview

An adapter which turns a normal flag change listener into a flag value change listener.

Since:

  • 5.5.0

Instance Method Summary collapse

Constructor Details

#initialize(flag_key, context, listener, eval_fn) ⇒ FlagValueChangeAdapter

Returns a new instance of FlagValueChangeAdapter.

Parameters:

Since:

  • 5.5.0



33
34
35
36
37
38
39
# File 'lib/ldclient-rb/impl/flag_tracker.rb', line 33

def initialize(flag_key, context, listener, eval_fn)
  @flag_key = flag_key
  @context = context
  @listener = listener
  @eval_fn = eval_fn
  @value = Concurrent::AtomicReference.new(@eval_fn.call(@flag_key, @context))
end

Instance Method Details

#update(flag_change) ⇒ Object

Parameters:

Since:

  • 5.5.0



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ldclient-rb/impl/flag_tracker.rb', line 44

def update(flag_change)
  return unless flag_change.key == @flag_key

  new_eval = @eval_fn.call(@flag_key, @context)
  old_eval = @value.get_and_set(new_eval)

  return if new_eval == old_eval

  @listener.update(
    LaunchDarkly::Interfaces::FlagValueChange.new(@flag_key, old_eval, new_eval))
end