Class: Innate::Fiber

Inherits:
Fiber
  • Object
show all
Defined in:
lib/innate/state/fiber.rb

Overview

Innate subclasses Fiber to enable lightweight request/respose-cycle local variables.

We do that by adding a state Hash to the Fiber instance on initalization which can be accessed by #[], #[]= and #key?. Other Hash methods are not necessary right now but may be added.

We subclass to keep your Ruby clean and polished.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Fiber

Returns a new instance of Fiber.



15
16
17
18
# File 'lib/innate/state/fiber.rb', line 15

def initialize(*args)
  super
  @state = {}
end

Instance Attribute Details

#stateObject

Returns the value of attribute state.



13
14
15
# File 'lib/innate/state/fiber.rb', line 13

def state
  @state
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
# File 'lib/innate/state/fiber.rb', line 20

def [](key)
  state[key]
end

#[]=(key, value) ⇒ Object



24
25
26
# File 'lib/innate/state/fiber.rb', line 24

def []=(key, value)
  state[key] = value
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/innate/state/fiber.rb', line 28

def key?(key)
  state.key?(key)
end

#keysObject



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

def keys
  state.keys
end