Class: Rediline::Timeline::User
- Inherits:
-
Object
- Object
- Rediline::Timeline::User
- Defined in:
- lib/rediline/timeline/user.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#field_name ⇒ Object
readonly
Returns the value of attribute field_name.
-
#lists ⇒ Object
readonly
Returns the value of attribute lists.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #count(type) ⇒ Object
- #destroy ⇒ Object
- #each(type) ⇒ Object
-
#initialize(field_name, user, block) ⇒ User
constructor
A new instance of User.
- #limit(count) ⇒ Object
- #list(name, &block) ⇒ Object
- #start_at(count) ⇒ Object
- #to_a(type) ⇒ Object
Constructor Details
#initialize(field_name, user, block) ⇒ User
Returns a new instance of User.
6 7 8 9 10 11 |
# File 'lib/rediline/timeline/user.rb', line 6 def initialize(field_name, user, block) @field_name, @user, @block = field_name, user @lists = {} @limit, @start_at = 10, 0 instance_eval(&block) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/rediline/timeline/user.rb', line 4 def block @block end |
#field_name ⇒ Object (readonly)
Returns the value of attribute field_name.
4 5 6 |
# File 'lib/rediline/timeline/user.rb', line 4 def field_name @field_name end |
#lists ⇒ Object (readonly)
Returns the value of attribute lists.
4 5 6 |
# File 'lib/rediline/timeline/user.rb', line 4 def lists @lists end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/rediline/timeline/user.rb', line 4 def user @user end |
Instance Method Details
#count(type) ⇒ Object
36 37 38 |
# File 'lib/rediline/timeline/user.rb', line 36 def count(type) Rediline.redis.llen(key(type)) end |
#destroy ⇒ Object
22 23 24 25 26 |
# File 'lib/rediline/timeline/user.rb', line 22 def destroy lists.each do |l| Rediline.redis.del key(l) end end |
#each(type) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/rediline/timeline/user.rb', line 13 def each(type) raise "you must provide a block" unless block_given? (@start_at..@limit).each do |i| data = Rediline.redis.lindex(key(type), i) next if data.nil? yield Rediline::Entry.new(data) end end |
#limit(count) ⇒ Object
44 45 46 47 |
# File 'lib/rediline/timeline/user.rb', line 44 def limit(count) @limit = count self end |
#list(name, &block) ⇒ Object
40 41 42 |
# File 'lib/rediline/timeline/user.rb', line 40 def list(name, &block) @lists[name] = instance_eval(&block) end |
#start_at(count) ⇒ Object
49 50 51 52 |
# File 'lib/rediline/timeline/user.rb', line 49 def start_at(count) @start_at = count self end |
#to_a(type) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/rediline/timeline/user.rb', line 28 def to_a(type) result = Array.new self.each(type) do |entry| result << entry end result end |