class TEF::ParameterStack::Override

Override class.

This class represents one 'access point' for the software, with which it can override certain values of the {Stack} it belongs to.

Using it is as simple as using a Hash: @example

override = Override.new(central_stack, 10);
override['SomeParam'] = 5
override['SomeParam'] = nil # Relinquish control over the value.

Attributes

level[R]

@return [Numeric] Level of this Override.

Higher levels mean higher priority. The highest-level
override that is active for any given key will determine
that key's value!

Public Class Methods

new(stack, init_level = 0) click to toggle source

Initialize an Override.

Values can be written into the Override immediately after creation. When the Override is no longer used, make sure to call {#destroy!}

@param [Stack] stack The stack to write to. @param [Numeric] init_level Level of this Override.

Can not be changed, is always the same for all keys!
# File lib/tef/ParameterStack/Override.rb, line 37
def initialize(stack, init_level = 0)
        raise ArgumentError, 'Handler must be CoreStack!' unless stack.is_a? Stack

        @stack = stack

        @level = init_level;
        @overrides = {}

        @valid_until = nil;

        @stack.add_override self
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/tef/ParameterStack/Override.rb, line 107
def <=>(other)
        return @level <=> other.level if other.level != @level
        return self.hash <=> other.hash
end
[](key) click to toggle source

@return The value of this Override for a given key. @note This will not be the global key. Use {Stack#[]} to retrieve

the currently active key.
# File lib/tef/ParameterStack/Override.rb, line 53
def [](key)
        @overrides[key]
end
[]=(key, new_value) click to toggle source

Set the value for the given key. Setting nil as value causes this Override to relinquish control @param key Hash-Key @param new_value User-defined value. If nil, relinquishes control.

# File lib/tef/ParameterStack/Override.rb, line 61
def []=(key, new_value)
        return if @overrides[key] == new_value

        if new_value.nil?
                delete(key)
                return
        end

        @overrides[key] = new_value
        @stack.override_claims self, key
end
delete(key) click to toggle source

Delete a value for the given key. Equivalent to calling {#[]=} nil

# File lib/tef/ParameterStack/Override.rb, line 85
def delete(key)
        return unless @overrides.include? key
        @overrides.delete key

        return unless @stack.active_overrides[key] == self

        @stack.recompute_single key
end
destroy!() click to toggle source

Destroy this Override.

This function MUST be called if the user no longer needs this object. It relinquishes control over all the values that this Override formerly held.

Note that nothing else is modified, and {Stack#add_override} could be used to re-add this Override.

# File lib/tef/ParameterStack/Override.rb, line 103
def destroy!
        @stack.remove_override self
end
include?(key) click to toggle source

@return [true,false] Whether this Override includes a given key

# File lib/tef/ParameterStack/Override.rb, line 74
def include?(key)
        @overrides.include? key
end
keys() click to toggle source

@return [Array] List of keys

# File lib/tef/ParameterStack/Override.rb, line 79
def keys
        @overrides.keys
end