
Research
/Security News
DuckDB npm Account Compromised in Continuing Supply Chain Attack
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
ActsAsFriendable provides a Friendship model, relevent scopes, and many instance methods to quickly and easily add Social Networking functionality to your Rails application.
ActsAsFriendable defines a "friendship" as a two-way relationship which is initiated by one user and approved by the other user. So, we have two states of a friendship (not-approved-yet or approved) and we have two directions of friendship relative to the current user: friendships requested by the current user (we’ll call these “direct” friendships), and friendships requested to the current user (we’ll call these “inverse” friendships).
Add ActsAsFriendable to your Gemfile:
gem 'acts_as_friendable'
And then install it with bundler by executing:
bundle install
Install and run the migrations:
rails g acts_as_friendable:install
rake db:migrate
ActsAsFriendable is meant to be used on one Active Record model. The model can be named anything you like, but it will most frequently be 'User'. Note: you'll need to manually add ActsAsFriendable to your model class.
class User < ActiveRecord::Base
include ActsAsFriendable
end
include ActsAsFriendable
adds all of the ActsAsFriendable goodness to the model.
Given the "friendship" definition in the Overview, we have 4 possible states of Friendship:
States #1 and #2 are simply what we will be calling "friends." They are approved relationships, no matter the direction. Because we don’t care who requested the friendship once it’s approved, we will group these together.
State #3 is what we call "pending friends." Other users with whom the current user has requested to be friends and are awaiting approval. These are out of of the control of the current user and just waiting to be approved or rejected.
State #4 is what we call "requested friends." Other users who have requested that the current user be their friend and are awaiting the approval of the current user. These are the actionable items for the current user to approve or reject. Ignoring a friend request simply deletes the non-approved Friendship (similar to Facebook). It doesn't tell the the other person they were reject but allows them to send another friend request if they want.
With that understanding we have the following scopes / "lookup" methods available to us:
class User < ActiveRecord::Base
include ActsAsFriendable
end
@user = User.find(1) # assuming there is a user in the database
@user.friendships
@user.inverse_friendships
@user.direct_friends
@user.inverse_friends
@user.pending_friends
@user.requested_friendships
@user.friends # => amalgamation of direct_friends and inverse_friends
# Additionally, we have several convenience methods to help in sorting, listing, finding, etc.
# provides a map of the current user's friend's ids
@user.friend_ids
# provides a map of ids of all current and requested friends of the current user
# - useful in querying for new friends
@user.pending_and_friend_ids
# includes the current user's id in the map of friend's ids
# - useful when you need to inlude the current user in a collection (Activities, Comments, Leaderboards, etc.)
@user.friend_ids_and_me
ActsAsFriendable uses RSpec for its test coverage. Inside the gem directory, you can run the specs with:
rake
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that acts_as_friendable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.