Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
= acts_as_rated
The ultimate rating system for ActiveRecord models. Highly flexible and configurable, while easy to use with the defaults. Supports 3 different ways to manage the statistics, and creates all the needed associations for easy access to everything.
Comes complete with the needed migrations code to make it easy to add to any project.
NOTE: It uses some advanced SQL constructs that might not be supported by all servers. It was tested on Postgres only. If you have patches/fixes for other databases, please send them and I will add them to the plugin. UPDATE: Thanks to work done by Tiago Serafim it now passes all but one tests on MySQL. And this test fails due to strangeness in the avg() function in MySQL, according to Tiago.
== Features
== Basic Details
Install
Rubyforge project
RDocs
Subversion
Agile Web Development directory
My blog with some comments about the plugin
Work done as part of Famundo development
Contact me at
== Changes
== TODO
== Example of usage:
=== Simple rating system Look at the file test/rating_test.rb for many usage examples covering all variations of the plugin.
class Book < ActiveRecord::Base acts_as_rated end
bill = User.find_by_name 'bill' jill = User.find_by_name 'jill' catch22 = Book.find_by_title 'Catch 22' hobbit = Book.find_by_title 'Hobbit'
catch22.rate 5, bill hobbit.rate 3, bill catch22.rate 1, jill hobbit.rate 5, jill
hobbit.rating_average # => 4 hobbit.rated_total # => 8 hobbit.rated_count # => 2
hobbit.unrate bill hobbit.rating_average # => 5 hobbit.rated_total # => 5 hobbit.rated_count # => 1
bks = Book.find_by_rating 5 # => [hobbit] bks = Book.find_by_rating 1..5 # => [catch22, hobbit]
usr = Book.find_rated_by jill # => [catch22, hobbit]
=== Migration The file test/fixtures/migrations/001_add_rating_tables.rb shows examples of all types of migration options.
See also the detailed documentation for the acts_as_rated method on how to declare it, and the rest of the documentation for how to generate the migration columns/files and how to use it.
class AddRatingTables < ActiveRecord::Migration def self.up ActiveRecord::Base.create_ratings_table
# Movies table has the columns for the ratings added while it's created
create_table(:movies) do |t|
t.column :title, :text
Movie.generate_ratings_columns t
end
# Cars table has the columns for the ratings added, but after the fact, using ALTER TABLE calls.
# Usually used if the model already exist and we want to add the ratings after the fact
create_table(:cars) do |t|
t.column :title, :text
end
Car.add_ratings_columns
end
def self.down
# Remove the columns we added
Car.remove_ratings_columns
drop_table :movies rescue nil
drop_table :cars rescue nil
ActiveRecord::Base.drop_ratings_table
end
end
== Testing the plugin
The plugin comes with a full set of tests, both for migrations and for the code itself. The framework was taken from the acts_as_versioned plugin, allowing it to run stand-alone in the test directory.
run the tests: rake test
In order for testing to work, you need to create a database (default name is acts_as_rated_plugin_test) and edit test/database.yml to make sure the login and password are correct. You can also change there the name of the database.
Testing defaults to postgresql, to change it set the environment variable DB to the driver you want to use: env DB='mysql' rake test
FAQs
Unknown package
We found that acts-as-rated 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.