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

Instance Method Details

#statevoid #statevoid #statevoid #statevoid #statevoid #statevoid

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.

Overloads:

  • #statevoid

    This method returns an undefined value.

  • #statevoid

    This method returns an undefined value.

  • #statevoid

    This method returns an undefined value.

  • #statevoid

    This method returns an undefined value.

  • #statevoid

    This method returns an undefined value.

  • #statevoid

    This method returns an undefined value.

Parameters:

Returns:

Raises:



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