Class: SimpleForum::UserActivity
- Inherits:
-
Object
- Object
- SimpleForum::UserActivity
- Defined in:
- app/models/simple_forum/user_activity.rb
Constant Summary collapse
- PATH =
Rails.root.join("file_store")
- FILE =
"simple_forum_activity"
Instance Attribute Summary collapse
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #[](object, default = Time.now) ⇒ Object
- #bang(object) ⇒ Object
- #destroy ⇒ Object
-
#initialize(user) ⇒ UserActivity
constructor
A new instance of UserActivity.
- #recent_activity?(object) ⇒ Boolean
- #store ⇒ Object
Constructor Details
#initialize(user) ⇒ UserActivity
Returns a new instance of UserActivity.
29 30 31 |
# File 'app/models/simple_forum/user_activity.rb', line 29 def initialize(user) @user = user end |
Instance Attribute Details
#user ⇒ Object (readonly)
Returns the value of attribute user.
9 10 11 |
# File 'app/models/simple_forum/user_activity.rb', line 9 def user @user end |
Class Method Details
Instance Method Details
#[](object, default = Time.now) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/models/simple_forum/user_activity.rb', line 41 def [](object, default=Time.now) ret = nil store.transaction(true) do user_hash = store[user.id] || {} object_hash = user_hash[key_for_object(object)] || {} ret = object_hash[object.id] end if user.try(:id) ret || default end |
#bang(object) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'app/models/simple_forum/user_activity.rb', line 51 def bang(object) store.transaction do user_hash = store[user.id] || {} object_hash = (user_hash[key_for_object(object)] ||= {}) object_hash[object.id] = Time.now store[user.id] = user_hash end if user.try(:id) nil end |
#destroy ⇒ Object
61 62 63 64 65 |
# File 'app/models/simple_forum/user_activity.rb', line 61 def destroy store.transaction do store.delete(user.id) end end |
#recent_activity?(object) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/simple_forum/user_activity.rb', line 11 def recent_activity?(object) self[object] > Time.now return false unless user.try(:id) if object.is_a?(SimpleForum::Forum) if recent_post = object.recent_post recent_post.created_at > self[object] else false end else #SimpleForum::Topic if object.last_updated_at object.last_updated_at > self[object] else false end end end |
#store ⇒ Object
37 38 39 |
# File 'app/models/simple_forum/user_activity.rb', line 37 def store self.class.store end |