GithubHelp home page GithubHelp logo

act_as_buddy's Introduction

act_as_buddy

act_as_buddy is a gem to allow any model to implement self relation. For eg: the friendships of a user can be implemented easily by self relation technique of act_as_buddy. Any Model can be buddied or lopped on to itself. Main uses would be for Users create friends etc.. Eg: User has many friends and friends are members of users table itself. This is expected to be heavily useful in social networking domain.

Installation

The master branch supports rails 3

Add the gem to the gemfile:

gem "act_as_buddy"

Run the generator:

rails generate act_as_buddy

This will generate a migration file as well as a model called BuddyMapper.Then do: rake db:migrate This will migrate the buddy_mappers table to database.

Rails <=3.0.0 is NOT SUPPORTED

The gem version does not work with rails <=3.0.0. Sorry guys its right time you guys think about an upgrade ;)

Usage

Setup

Make your model(s) that you want to allow to be buddied act_as_buddy, just add the mixin:

class User < ActiveRecord::Base
  ...
  act_as_buddeable
  ...
end

act_as_buddy methods

To have an object start buddying another object of same model use the following:

user1 = User.first(1)
user2 = User.first(2)
user1.add_buddy(user2) # Creates a messaage of containing the id of buddied records.

To remove a buddy from buddy list

user1.remove_buddy(user2) # Returns a message saying that the object ids are un-buddied.

You can check to see if an object is buddied to other object of same type:

user1.is_a_buddy_of?(user2) # Returns true or false

To get the total number (count) of buddies of an object.

user1.get_buddy_count # Returns an integer

To get the actual list of all buddies of an object.

user1.fetch_all_buddies # Returns an array of all buddied objects

To find a buddy of an object with a field exactly matching a value

user1.find_buddies_with(:name => "ashik")
# Returns the buddied object of the parent object matching the field value exactly. Eg: friends of user1 with name='ashik'.

To find buddies of an object with a field matching a value like argument string.

user1.find_buddies_like(:name => "ash")
# Returns an array of all buddied objects of the parent object having name similar to field value. Eg: friends of user1 with name like 'ash'.result - [<#User3ashik>]

To add multiple buddies to the buddy list (or ‘Bulk Buddying’) of an object.

user1.add_multiple_buddies(args)  
# args is an array of all buddies to be added. They should all the of same type as parent object.

To remove multiple buddies from the buddy list (or ‘Bulk Buddy Removal’) of an object.

user1.remove_multiple_buddies(args)  
# args is an array of all buddies to be added. They should all the of same type as parent object.

To remove all buddies from the buddy list (or ‘Bulk Buddy Removal’) of an object.

user1.remove_all_buddies()

Testing the Gem

  • Fork the project.

  • Goto the root folder.

  • Execute ‘bundle install’.

  • Execute ‘bundle exec dummier’.

  • This will create the test app and all dependencies for testing.

  • Execute ‘rake test’ or simply ‘rake’.

Comments/Requests

If anyone has comments or questions please let me know ([email protected] or [email protected]). If you have updates or patches or want to contribute I would love to see what you have or want to add.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally (act_as_buddy uses Shoulda and Dummier)

  • Send me a pull request. Bonus points for topic branches.

Contributers

This list is open to all. You are all welcome :).

Copyright © 2013 kannancet([email protected], [email protected]). See LICENSE.txt for further details.

act_as_buddy's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.