Class: LaunchDarkly::Impl::FlagTracker::FlagValueChangeAdapter
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::FlagTracker::FlagValueChangeAdapter
- 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.
Instance Method Summary collapse
-
#initialize(flag_key, context, listener, eval_fn) ⇒ FlagValueChangeAdapter
constructor
A new instance of FlagValueChangeAdapter.
- #update(flag_change) ⇒ Object
Constructor Details
#initialize(flag_key, context, listener, eval_fn) ⇒ FlagValueChangeAdapter
Returns a new instance of FlagValueChangeAdapter.
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
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 |