Module: Authorize::Redis::ModelReference

Included in:
Graph::Edge
Defined in:
lib/authorize/redis/model_reference.rb

Overview

Support foreign keys that reference Redis::Base-like models.

Class Method Summary collapse

Class Method Details

.load_reference(key, klass) ⇒ Object

Load the model whose key is held in the given string key.



6
7
8
9
# File 'lib/authorize/redis/model_reference.rb', line 6

def load_reference(key, klass)
  reference = klass.db.get(key)
  reference && klass.load(reference)
end

.set_reference(key, model) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/authorize/redis/model_reference.rb', line 11

def set_reference(key, model)
  if model
    Authorize::Redis::String.db.set(key, model.id)
  else
    Authorize::Redis::String.db.del(key) && nil
  end
end