Ravn::BDE::

StateProxy class

A state proxy for getting and setting values for a Bolt.

Attributes

bolt_id R

The bolt id used as a prefix for each value in the store.

manager R

The state manager to get/set values

Public Class Methods

new( manager, bolt_id )

Create a StateProxy proxy that will get and set values via the given manager with the specified label.

# File lib/ravn/bde/state_proxy.rb, line 20
def initialize( manager, bolt_id )
        @manager = manager
        @bolt_id = bolt_id.freeze
end

Public Instance Methods

[]( key, default=nil, &default_callback )
Alias for: fetch
[]=( key, value )
Alias for: store
fetch( key, default=nil, &default_callback )

Fetch the value associated with key from the state manager. If the result is nil, return the result of calling the default_callback if it’s defined or the default value otherwise.

# File lib/ravn/bde/state_proxy.rb, line 42
def fetch( key, default=nil, &default_callback )
        # self.log.debug "Fetching %p as %p from manager: %p" % [ key, self.bolt_id, self.manager ]
        rval = self.manager.ask!( [:fetch, self.bolt_id, key] )
        # self.log.debug "  returning: %p" % [ rval ]

        if rval.nil?
                rval = default_callback ? default_callback[ key ] : default
        end

        return rval.freeze
end
Also aliased as: []
store( key, value )

Store the given value at key via the state manager.

# File lib/ravn/bde/state_proxy.rb, line 57
def store( key, value )
        # raise ArgumentError, "Can't store a mutable value" unless value.frozen?
        # :TODO: Could this be a tell?
        self.manager.ask!( [:store, self.bolt_id, key, value] )
end
Also aliased as: []=