Class: LaunchDarkly::Impl::EvaluatorStack Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::EvaluatorStack
- Defined in:
- lib/ldclient-rb/impl/evaluator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A helper class for managing cycle detection.
Each time a method sees a new flag or segment, they can push that object's key onto the stack. Once processing for that object has finished, you can call pop to remove it.
Because the most common use case would be a flag or segment without ANY prerequisites, this stack has a small optimization in place-- the stack is not created until absolutely necessary.
Instance Method Summary collapse
- #include?(key) ⇒ Boolean private
-
#initialize(original) ⇒ EvaluatorStack
constructor
private
A new instance of EvaluatorStack.
- #pop ⇒ Object private
- #push(key) ⇒ Object private
Constructor Details
#initialize(original) ⇒ EvaluatorStack
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EvaluatorStack.
63 64 65 66 67 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 63 def initialize(original) @original = original # @type [Array<String>, nil] @stack = nil end |
Instance Method Details
#include?(key) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 98 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 93 def include?(key) return true if key == @original return false if @stack.nil? @stack.include? key end |
#pop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 84 def pop return if @stack.nil? || @stack.empty? @stack.pop end |
#push(key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 70 def push(key) # No need to store the key if we already have a record in our instance # variable. return if @original == key # The common use case is that flags/segments won't have prereqs, so we # don't allocate the stack memory until we absolutely must. if @stack.nil? @stack = [] end @stack.push(key) end |