Class: Fibre::Scope

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fiber) ⇒ Scope

Returns a new instance of Scope.



30
31
32
33
# File 'lib/fibre/scope.rb', line 30

def initialize(fiber)
  @fiber = fiber
  @mocks = []
end

Instance Attribute Details

#fiberObject

Returns the value of attribute fiber.



4
5
6
# File 'lib/fibre/scope.rb', line 4

def fiber
  @fiber
end

#mocksObject

Returns the value of attribute mocks.



3
4
5
# File 'lib/fibre/scope.rb', line 3

def mocks
  @mocks
end

Class Method Details

.scopeObject



8
9
10
11
12
13
14
15
# File 'lib/fibre/scope.rb', line 8

def scope
  raise "nested scopes" if Fiber.current[:scope]
  Fiber.current[:scope] = self.new(Fiber.current)
  res = yield
  Fiber.current[:scope] = nil
  Fiber.yield!
  res
end

.scope?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/fibre/scope.rb', line 17

def scope?
  !!Fiber.current[:scope]
end

.sync {|mock| ... } ⇒ Object

Yields:

  • (mock)


21
22
23
24
25
26
27
# File 'lib/fibre/scope.rb', line 21

def sync
  scope = Fiber.current[:scope]
  mock = Fibre::Mock.new(scope)
  scope.mocks << mock
  yield(mock) if block_given?
  mock
end

Instance Method Details

#checkObject



35
36
37
# File 'lib/fibre/scope.rb', line 35

def check
  fiber.resume if @mocks.all?(&:completed?)
end