Sha256: 289937b015836729c4d23baae6cc40eec32866830fab3e154574d55a41cf0464

Contents?: true

Size: 982 Bytes

Versions: 4

Compression:

Stored size: 982 Bytes

Contents

module Blendris

  # RedisReference is a wrapper to a Redis string value and serves
  # as a pointer to another blendris object.

  class RedisReference < RedisReferenceBase

    def ref
      @ref ||= RedisString.new(@key)
    end

    def set(obj)
      old_obj = self.get if @reverse
      modified = false
      refkey = self.class.cast_to_redis(obj, @options)

      if refkey == nil
        ref.set nil
        modified = true
      elsif refkey != ref.get
        ref.set refkey
        apply_reverse_add obj
        modified = true
      end

      if modified
        apply_reverse_delete(old_obj)
        notify_changed
      end

      obj
    end

    def get
      self.class.cast_from_redis ref.get
    end

    def assign_ref(value)
      self.set value
    end

    def remove_ref(value)
      self.set nil
    end

    def references(value)
      refval = ref.get

      return true if refval.nil? && value.nil?
      return refval == value.key
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blendris-1.2 lib/blendris/reference.rb
blendris-1.1 lib/blendris/reference.rb
blendris-1.0 lib/blendris/reference.rb
blendris-0.6 lib/blendris/reference.rb