Class: Puppet::Pops::Types::RecursionGuard Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeRecursionGuard

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

#stateObject (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

Parameters:

  • instance (Object)

    the instance to add

Returns:

  • (Integer)

    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

Parameters:

  • instance (Object)

    the instance to add

Returns:

  • (Integer)

    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

Parameters:

  • instance (Object)

    the instance to check

Returns:

  • (Integer)

    the resulting state



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

Parameters:

  • instance (Object)

    the instance to check

Returns:

  • (Integer)

    the resulting state



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_countObject

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.

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_countObject

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.

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

Parameters:

  • instance (Object)

    the instance to add

Yields:

Returns:

  • (Object)

    the result of yielding



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

Parameters:

  • instance (Object)

    the instance to add

Yields:

Returns:

  • (Object)

    the result of yielding



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