
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Resonate provides a relational feature to your Rails application, such as follow, like, and so on.
Add this line to your application's Gemfile:
gem 'resonate'
And then execute:
$ bundle
Resonate supports two way to add relational feature.
Following example shows about User model, however, you can apply to any models.
This case adds follow feature to User model.
At first, generate User and Follow model:
$ bin/rails g model User
$ bin/rails g model Follow user_id:integer target_user_id:integer
And migrate:
$ bin/rake db:migrate
Then, define Resonatable
module to app/models/concerns/resonatable.rb
:
module Resonatable
include Resonate
resonate :user, with: :user, by: :follow
end
At last, include this module from each models:
class User < ActiveRecord::Base
include Resonatable
end
class Follow < ActiveRecord::Base
include Resonatable
end
That's it. User instance has been added following methods:
Example:
user = User.create
other_user = User.create
# Follow
user.follow other_user
user.following?(other_user) #=> true
user.following #=> <ActiveRecord::Associations::CollectionProxy [#<User id: 2, created_at: "2015-01-10 01:57:52", updated_at: "2015-01-10 01:57:52">]>
other_user.followed_by?(user) #=> true
other_user.followers #=> <ActiveRecord::Associations::CollectionProxy [#<User id: 1, created_at: "2015-01-10 01:57:42", updated_at: "2015-01-10 01:57:42">]>
# Unfollow
user.unfollow other_user
user.following?(other_user) #=> false
user.following #=> <ActiveRecord::Associations::CollectionProxy []>
other_user.followed_by?(user) #=> false
other_user.followers #=> <ActiveRecord::Associations::CollectionProxy []>
This case adds like feature to User and Post model.
module Resonatable
include Resonate
resonate :user, with: :post, by: :like
end
class User < ActiveRecord::Base
include Resonatable
end
class Post < ActiveRecord::Base
include Resonatable
end
class Like < ActiveRecord::Base
include Resonatable
end
User and Post instance has been added following methods:
At the same time, some resonate
methods are able to be defined:
module Resonatable
include Resonate
resonate :user, with: :user, by: :follow
resonate :user, with: :post, by: :like
end
If you want to use other foreign key name, you can define it by :foreign_key
option.
resonate :user, with: :post, by: :like, foreign_key: :post_id # Default is `:target_post_id`
FAQs
Unknown package
We found that resonate 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.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.