Mark_as_anything is a project mainly written in Ruby, based on the MIT license.
Simple plugin for marking objects with flags like 'read' or 'starred'
A simple way of marking objects with things like 'read' or 'starred'.
Install it as a plugin. Then run ./script/generate mark_as_anything
to create a migration.
# models
class User < ActiveRecord::Base
markable_actor
end
class Message < ActiveRecord::Base
markable_with :read
end
# usage
@message.is_read_by?(@user) #=> false
@message.mark_as_read_by(@user)
@message.is_read_by?(@user) #=> true
Message.read_by(@user) #=> fetches messages read by user
In the example above the markable object will receive these methods:
is_read_by?(actor)
mark_as_read_by(actor)
unmark_as_read_by(actor)
unmark_as_read_by_all
The actor object will have these methods added:
has_read?(object)
markable_actor
(TODO)unread_messages = Message.all - Message.read_by(@user)
. Everybody's situation is different so it's
difficult to account for all cases.Copyright (c) 2010 Ebony Charlton, released under the MIT license