Class: Tractor::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/tractor/model/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, klass) ⇒ Association

Returns a new instance of Association.



24
25
26
27
# File 'lib/tractor/model/base.rb', line 24

def initialize(key, klass)
  self.klass = klass
  self.key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



22
23
24
# File 'lib/tractor/model/base.rb', line 22

def key
  @key
end

#klassObject

Returns the value of attribute klass.



22
23
24
# File 'lib/tractor/model/base.rb', line 22

def klass
  @klass
end

Instance Method Details

#allObject



45
46
47
# File 'lib/tractor/model/base.rb', line 45

def all
  ids.inject([]){|o, id| o << klass.find_by_id(id); o }
end

#countObject



41
42
43
# File 'lib/tractor/model/base.rb', line 41

def count
  Tractor.redis.scard(key)
end

#delete(id) ⇒ Object



33
34
35
# File 'lib/tractor/model/base.rb', line 33

def delete(id)
  Tractor.redis.srem(key, id)
end

#idsObject



37
38
39
# File 'lib/tractor/model/base.rb', line 37

def ids
  Tractor.redis.smembers(key) || []
end

#push(val) ⇒ Object



29
30
31
# File 'lib/tractor/model/base.rb', line 29

def push(val)
  Tractor.redis.sadd(key, val.id)
end