Class: Tractor::Association
- Inherits:
-
Object
- Object
- Tractor::Association
- Defined in:
- lib/tractor/model/base.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#klass ⇒ Object
Returns the value of attribute klass.
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #delete(id) ⇒ Object
- #ids ⇒ Object
-
#initialize(key, klass) ⇒ Association
constructor
A new instance of Association.
- #push(val) ⇒ Object
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
#key ⇒ Object
Returns the value of attribute key.
22 23 24 |
# File 'lib/tractor/model/base.rb', line 22 def key @key end |
#klass ⇒ Object
Returns the value of attribute klass.
22 23 24 |
# File 'lib/tractor/model/base.rb', line 22 def klass @klass end |
Instance Method Details
#all ⇒ Object
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 |
#count ⇒ Object
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 |