lib/blendris/reference_base.rb in blendris-0.0.2 vs lib/blendris/reference_base.rb in blendris-0.0.3
- old
+ new
@@ -1,17 +1,21 @@
module Blendris
+ # RedisReferenceBase holds the methods that are common to
+ # RedisReference objects and RedisReferenceSet objects.
+
class RedisReferenceBase
include RedisNode
extend RedisAccessor
def initialize(key, options = {})
@model = options[:model]
@key = sanitize_key(key)
@reverse = options[:reverse]
@options = options
+ @on_change = options[:on_change]
@klass = options[:class] || Model
@klass = constantize(camelize @klass) if @klass.kind_of? String
unless @klass.ancestors.include? Model
@@ -50,10 +54,10 @@
def self.cast_from_redis(refkey, options = {})
expect = options[:class] || Model
expect = constantize(expect) if expect.kind_of? String
expect = Model unless expect.ancestors.include? Model
- klass = constantize(redis.get(prefix + refkey)) if refkey
+ klass = constantize(redis.get(refkey)) if refkey
if klass == nil
nil
elsif klass.ancestors.include? expect
klass.new refkey