Class: Activist::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/activist/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actorObject (readonly)

Returns the value of attribute actor.



3
4
5
# File 'lib/activist/stream.rb', line 3

def actor
  @actor
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/activist/stream.rb', line 3

def name
  @name
end

#subscribersObject (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(options={})
  options[:offset] ||= 0
  options[:limit] ||= size
  options[:offset], options[:limit] = options[:offset].to_i, options[:limit].to_i
  activities = Redis.execute.lrange(to_key, options[:offset], options[:offset] + options[:limit])
  ::ActivistStatus.where(:id => activities)
end

#destroyObject



29
30
31
# File 'lib/activist/stream.rb', line 29

def destroy
  Redis.execute.del(to_key)
end

#sizeObject



25
26
27
# File 'lib/activist/stream.rb', line 25

def size
  @size ||= Redis.execute.llen(to_key)
end

#to_keyObject



33
34
35
# File 'lib/activist/stream.rb', line 33

def to_key
  "#{actor.class}.#{actor.id}:#{name}"
end