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.



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

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
16
# File 'lib/fibre/scope.rb', line 8

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

.scope?Boolean

Returns:

  • (Boolean)


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

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

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

Yields:

  • (mock)


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

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



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

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