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.
20 21 22 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 20 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.
13 14 15 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 13 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
91 92 93 94 95 96 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 91 def add_that(instance) if (@state & SELF_RECURSION_IN_THAT) == 0 @state = @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
81 82 83 84 85 86 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 81 def add_this(instance) if (@state & SELF_RECURSION_IN_THIS) == 0 @state = @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
34 35 36 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 34 def recursive_that?(instance) instance_variable_defined?(:@recursive_that_map) && @recursive_that_map.has_key?(instance.object_id) 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
27 28 29 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 27 def recursive_this?(instance) instance_variable_defined?(:@recursive_this_map) && @recursive_this_map.has_key?(instance.object_id) 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.
104 105 106 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 104 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.
99 100 101 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 99 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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 61 def with_that(instance) if (@state & SELF_RECURSION_IN_THAT) == 0 tc = that_count @state = @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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/pops/types/recursion_guard.rb', line 41 def with_this(instance) if (@state & SELF_RECURSION_IN_THIS) == 0 tc = this_count @state = @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 |