Class: LaunchDarkly::Impl::DependencyTracker Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DependencyTracker
- Defined in:
- lib/ldclient-rb/impl/dependency_tracker.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.
Class Method Summary collapse
- .compute_dependencies_from(from_kind, from_item, logger = nil) ⇒ Set private
- .segment_keys_from_clauses(clauses) ⇒ Object private
Instance Method Summary collapse
-
#add_affected_items(items_out, initial_modified_item) ⇒ Object
private
Populates the given set with the union of the initial item and all items that directly or indirectly depend on it (based on the current state of the dependency graph).
-
#initialize(logger = nil) ⇒ DependencyTracker
constructor
private
A new instance of DependencyTracker.
-
#reset ⇒ Object
private
Clear any tracked dependencies and reset the tracking state to a clean slate.
-
#update_dependencies_from(from_kind, from_key, from_item) ⇒ Object
private
Updates the dependency graph when an item has changed.
Constructor Details
#initialize(logger = nil) ⇒ DependencyTracker
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 DependencyTracker.
6 7 8 9 10 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 6 def initialize(logger = nil) @from = {} @to = {} @logger = logger end |
Class Method Details
.compute_dependencies_from(from_kind, from_item, logger = nil) ⇒ Set
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.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 58 def self.compute_dependencies_from(from_kind, from_item, logger = nil) # Check for deleted items (matches Python: from_item.get('deleted', False)) return Set.new if from_item.nil? || (from_item.is_a?(Hash) && from_item[:deleted]) # Deserialize hash to model object if needed (matches Python: from_kind.decode(from_item) if isinstance(from_item, dict)) from_item = if from_item.is_a?(Hash) LaunchDarkly::Impl::Model.deserialize(from_kind, from_item, logger) else from_item end if from_kind == DataStore::FEATURES && from_item.is_a?(LaunchDarkly::Impl::Model::FeatureFlag) prereq_keys = from_item.prerequisites.map { |prereq| {kind: from_kind, key: prereq.key} } segment_keys = from_item.rules.flat_map { |rule| DependencyTracker.segment_keys_from_clauses(rule.clauses) } results = Set.new(prereq_keys) results.merge(segment_keys) elsif from_kind == DataStore::SEGMENTS && from_item.is_a?(LaunchDarkly::Impl::Model::Segment) kind_and_keys = from_item.rules.flat_map do |rule| DependencyTracker.segment_keys_from_clauses(rule.clauses) end Set.new(kind_and_keys) else Set.new end end |
.segment_keys_from_clauses(clauses) ⇒ 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.
42 43 44 45 46 47 48 49 50 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 42 def self.segment_keys_from_clauses(clauses) clauses.flat_map do |clause| if clause.op == :segmentMatch clause.values.map { |value| {kind: DataStore::SEGMENTS, key: value }} else [] end end end |
Instance Method Details
#add_affected_items(items_out, initial_modified_item) ⇒ 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.
Populates the given set with the union of the initial item and all items that directly or indirectly depend on it (based on the current state of the dependency graph).
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 100 def add_affected_items(items_out, initial_modified_item) return if items_out.include? initial_modified_item items_out.add(initial_modified_item) affected_items = @to[initial_modified_item] return if affected_items.nil? affected_items.each do |affected_item| add_affected_items(items_out, affected_item) end end |
#reset ⇒ 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.
Clear any tracked dependencies and reset the tracking state to a clean slate.
88 89 90 91 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 88 def reset @from.clear @to.clear end |
#update_dependencies_from(from_kind, from_key, from_item) ⇒ 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.
Updates the dependency graph when an item has changed.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ldclient-rb/impl/dependency_tracker.rb', line 19 def update_dependencies_from(from_kind, from_key, from_item) from_what = { kind: from_kind, key: from_key } updated_dependencies = DependencyTracker.compute_dependencies_from(from_kind, from_item, @logger) old_dependency_set = @from[from_what] unless old_dependency_set.nil? old_dependency_set.each do |kind_and_key| deps_to_this_old_dep = @to[kind_and_key] deps_to_this_old_dep&.delete(from_what) end end @from[from_what] = updated_dependencies updated_dependencies.each do |kind_and_key| deps_to_this_new_dep = @to[kind_and_key] if deps_to_this_new_dep.nil? deps_to_this_new_dep = Set.new @to[kind_and_key] = deps_to_this_new_dep end deps_to_this_new_dep.add(from_what) end end |