Class: Activist::Stream
- Inherits:
-
Object
- Object
- Activist::Stream
- Defined in:
- lib/activist/stream.rb
Instance Attribute Summary collapse
-
#actor ⇒ Object
readonly
Returns the value of attribute actor.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Instance Method Summary collapse
- #all(options = {}) ⇒ Object
- #destroy ⇒ Object
-
#initialize(name, actor, block) ⇒ Stream
constructor
A new instance of Stream.
- #size ⇒ Object
- #to_key ⇒ Object
Constructor Details
#initialize(name, actor, block) ⇒ Stream
Returns a new instance of Stream.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/activist/stream.rb', line 5 def initialize(name, actor, block) @name = name.to_sym @actor = actor scoped = block.call(actor) @subscribers = case scoped when Symbol actor.class.send(scoped) when Array scoped end end |
Instance Attribute Details
#actor ⇒ Object (readonly)
Returns the value of attribute actor.
3 4 5 |
# File 'lib/activist/stream.rb', line 3 def actor @actor end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/activist/stream.rb', line 3 def name @name end |
#subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
3 4 5 |
# File 'lib/activist/stream.rb', line 3 def subscribers @subscribers end |
Instance Method Details
#all(options = {}) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/activist/stream.rb', line 17 def all(={}) [:offset] ||= 0 [:limit] ||= size [:offset], [:limit] = [:offset].to_i, [:limit].to_i activities = Redis.execute.lrange(to_key, [:offset], [:offset] + [:limit]) ::ActivistStatus.where(:id => activities) end |
#destroy ⇒ Object
29 30 31 |
# File 'lib/activist/stream.rb', line 29 def destroy Redis.execute.del(to_key) end |
#size ⇒ Object
25 26 27 |
# File 'lib/activist/stream.rb', line 25 def size @size ||= Redis.execute.llen(to_key) end |
#to_key ⇒ Object
33 34 35 |
# File 'lib/activist/stream.rb', line 33 def to_key "#{actor.class}.#{actor.id}:#{name}" end |