Class: Ramaze::State

Inherits:
Object show all
Defined in:
lib/ramaze/snippets/ramaze/state.rb

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.



3
4
5
# File 'lib/ramaze/snippets/ramaze/state.rb', line 3

def initialize
  @core = detect
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/ramaze/snippets/ramaze/state.rb', line 16

def [](key)
  @core.current[key]
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/ramaze/snippets/ramaze/state.rb', line 20

def []=(key, value)
  @core.current[key] = value
end

#detectObject



7
8
9
10
11
12
13
14
# File 'lib/ramaze/snippets/ramaze/state.rb', line 7

def detect
  require 'fiber'
  @extract = :resume
  Ramaze::Fiber
rescue LoadError
  @extract = :value
  ::Thread
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ramaze/snippets/ramaze/state.rb', line 24

def key?(key)
  @core.current.key?(key)
end

#wrap(&block) ⇒ Object



28
29
30
# File 'lib/ramaze/snippets/ramaze/state.rb', line 28

def wrap(&block)
  @core.new(&block).send(@extract)
end