Module: Fiber::Storage

Included in:
Fiber
Defined in:
lib/fiber/storage.rb,
lib/fiber/storage/version.rb

Overview

Provides compatibility shims for fiber storage.

Constant Summary collapse

VERSION =
"1.0.1"

Instance Method Summary collapse

Instance Method Details

#__storage__Object



37
38
39
# File 'lib/fiber/storage.rb', line 37

def __storage__
	@storage ||= {}
end

#initialize(*arguments, storage: true, **options, &block) ⇒ Object

Initialize the fiber with the given storage.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fiber/storage.rb', line 13

def initialize(*arguments, storage: true, **options, &block)
	case storage
	when true
		@storage = Fiber.current.storage
	else
		raise TypeError, "Storage must be a hash!" unless storage.is_a?(Hash)
		
		@storage = storage
	end
	
	super(*arguments, **options, &block)
end

#storageObject

The storage associated with this fiber.



32
33
34
# File 'lib/fiber/storage.rb', line 32

def storage
	@storage.dup
end

#storage=(hash) ⇒ Object

Set the storage associated with this fiber, clearing any previous storage.



27
28
29
# File 'lib/fiber/storage.rb', line 27

def storage=(hash)
	@storage = hash.dup
end