Module: Prosody::State::Vending
- Included in:
- Context
- Defined in:
- lib/prosody/state.rb,
sig/state.rbs
Overview
Adds keyed-state vending to the native context.
Instance Method Summary collapse
-
#state(definition) ⇒ ValueState, ...
Vends the typed keyed-state handle for
definition.
Instance Method Details
#state ⇒ void #state ⇒ void #state ⇒ void #state ⇒ void #state ⇒ void #state ⇒ void
Vends the typed keyed-state handle for definition.
Handles are cached per context by kind, payload, and name, so repeated vends within one handler invocation return the same wrapper.
193 194 195 196 197 198 199 200 |
# File 'lib/prosody/state.rb', line 193 def state(definition) cache = (@state_handles ||= {}) cache_key = "#{definition.kind}:#{definition.payload}:#{definition.name}" return cache[cache_key] if cache.key?(cache_key) native = public_send(definition.access.vend_method, definition.name) cache[cache_key] = Prosody.const_get(definition.access.wrapper).new(native) end |