Class: Contracts::ExecutionGuard

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts.rb

Class Method Summary collapse

Class Method Details

.active?(key) ⇒ Boolean

Returns:

  • (Boolean)


158
# File 'lib/contracts.rb', line 158

def self.active?(key) = stack.include?(key)

.current_stackObject



160
# File 'lib/contracts.rb', line 160

def self.current_stack = stack.dup.freeze

.depthObject



159
# File 'lib/contracts.rb', line 159

def self.depth = stack.length

.enter(key) ⇒ Object



162
163
164
165
166
167
168
169
# File 'lib/contracts.rb', line 162

def self.enter(key)
  return yield(false) if active?(key)

  stack << key
  yield(true)
ensure
  stack.pop if stack.last == key
end

.stackObject



153
154
155
156
# File 'lib/contracts.rb', line 153

def self.stack
  stores = Thread.current[:contracts_execution_guard] ||= {}
  stores[Fiber.current] ||= []
end