Class: Puppet::Pops::Types::RecursionGuard Private
- Defined in:
- lib/puppet/pops/types/recursion_guard.rb
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.
Constant Summary collapse
- NO_SELF_RECURSION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0
- SELF_RECURSION_IN_THIS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1
- SELF_RECURSION_IN_THAT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2
- SELF_RECURSION_IN_BOTH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
3
Instance Attribute Summary collapse
- #state ⇒ Object readonly private
Instance Method Summary collapse
-
#add_that(instance) ⇒ Integer
private
Add the given argument as ‘that’ and return the resulting state.
-
#add_this(instance) ⇒ Integer
private
Add the given argument as ‘this’ and return the resulting state.
-
#initialize ⇒ RecursionGuard
constructor
private
A new instance of RecursionGuard.
-
#recursive_that?(instance) ⇒ Integer
private
Checks if recursion was detected for the given argument in the ‘that’ context.
-
#recursive_this?(instance) ⇒ Integer
private
Checks if recursion was detected for the given argument in the ‘this’ context.
-
#that_count ⇒ Object
private
The number of objects added to the ‘that` map.
-
#this_count ⇒ Object
private
The number of objects added to the ‘this` map.
-
#with_that(instance) {|@state| ... } ⇒ Object
private
Add the given argument as ‘that’ invoke the given block with the resulting state.
-
#with_this(instance) {|@state| ... } ⇒ Object
private
Add the given argument as ‘this’ invoke the given block with the resulting state.
Constructor Details
#initialize ⇒ RecursionGuard
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 RecursionGuard.
25 26 27 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 25 def initialize @state = NO_SELF_RECURSION end |
Instance Attribute Details
#state ⇒ Object (readonly)
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.
18 19 20 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 18 def state @state end |
Instance Method Details
#add_that(instance) ⇒ Integer
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.
Add the given argument as ‘that’ and return the resulting state
96 97 98 99 100 101 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 96 def add_that(instance) if (@state & SELF_RECURSION_IN_THAT) == 0 @state |= SELF_RECURSION_IN_THAT if that_put(instance) end @state end |
#add_this(instance) ⇒ Integer
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.
Add the given argument as ‘this’ and return the resulting state
86 87 88 89 90 91 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 86 def add_this(instance) if (@state & SELF_RECURSION_IN_THIS) == 0 @state |= SELF_RECURSION_IN_THIS if this_put(instance) end @state end |
#recursive_that?(instance) ⇒ Integer
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.
Checks if recursion was detected for the given argument in the ‘that’ context
39 40 41 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 39 def recursive_that?(instance) instance_variable_defined?(:@recursive_that_map) && @recursive_that_map.has_key?(instance.object_id) # rubocop:disable Lint/HashCompareByIdentity end |
#recursive_this?(instance) ⇒ Integer
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.
Checks if recursion was detected for the given argument in the ‘this’ context
32 33 34 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 32 def recursive_this?(instance) instance_variable_defined?(:@recursive_this_map) && @recursive_this_map.has_key?(instance.object_id) # rubocop:disable Lint/HashCompareByIdentity end |
#that_count ⇒ 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.
Returns the number of objects added to the ‘that` map.
109 110 111 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 109 def that_count instance_variable_defined?(:@that_map) ? @that_map.size : 0 end |
#this_count ⇒ 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.
Returns the number of objects added to the ‘this` map.
104 105 106 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 104 def this_count instance_variable_defined?(:@this_map) ? @this_map.size : 0 end |
#with_that(instance) {|@state| ... } ⇒ 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.
Add the given argument as ‘that’ invoke the given block with the resulting state
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 66 def with_that(instance) if (@state & SELF_RECURSION_IN_THAT) == 0 tc = that_count @state |= SELF_RECURSION_IN_THAT if that_put(instance) if tc < that_count # recursive state detected result = yield(@state) # pop state @state &= ~SELF_RECURSION_IN_THAT @that_map.delete(instance.object_id) return result end end yield(@state) end |
#with_this(instance) {|@state| ... } ⇒ 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.
Add the given argument as ‘this’ invoke the given block with the resulting state
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 46 def with_this(instance) if (@state & SELF_RECURSION_IN_THIS) == 0 tc = this_count @state |= SELF_RECURSION_IN_THIS if this_put(instance) if tc < this_count # recursive state detected result = yield(@state) # pop state @state &= ~SELF_RECURSION_IN_THIS @this_map.delete(instance.object_id) return result end end yield(@state) end |