An active record bookmark system developed using ruby on rails applying domain driven design and test driven development principles.
For rails 4 support use branch v0.0.7-stable.
For rails 5 support use branch v0.1.1-stable.
This gem is heavily influenced by cmer/socialization.
Add this line to your application's Gemfile:
gem 'bookmark_system'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bookmark_system
$ rails g bookmark_system
Let's suppose for a moment that you have a blog application and a User can bookmark a Post or several Post models. The user model becomes the bookmarker and the post model becomes the bookmarkee.
class Post < ActiveRecord::Base
act_as_bookmarkee
validates :content, presence: true
end
class User < ActiveRecord::Base
act_as_bookmarker
validates :username, { presence: true, uniqueness: true }
end
post.is_bookmarkee? # returns true
post.bookmarked_by?(user) # returns true if user bookmarks the post object, false otherwise
post.bookmarkers_by(User) # returns a scope of BookmarkSystem::Bookmark join model that belongs to the post object and belongs to bookmarker objects of type User
user.is_bookmarker? # returns true
user.bookmark(post) # Creates an instance of BookmarkSystem::Bookmark join model associating the user object and the post object, returns true if succeded, false otherwise
user.unbookmark(post) # Destroys an instance of BookmarkSystem::Bookmark join model that associates the user object and the post object, returns true if succeded, false otherwise
user.toggle_bookmark(post) # Bookmarks / unbookmarks the post
user.bookmarks?(post) # returns true if the user object bookmarks the post object, false otherwise
user.bookmarkees_by(Post) # returns a scope of BookmarkSystem::Bookmark join model that belongs to the user object and belongs to bookmarkee objects of type Post
For more information read the api documentation.
- Fork it ( https://github.com/pmviva/bookmark_system/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request