Skip to content

Commit

Permalink
Initial import into Rubyforge
Browse files Browse the repository at this point in the history
git-svn-id: svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated@1 d2fe85f9-699c-4bcc-83cd-509c172d722e
  • Loading branch information
guynaor committed Feb 4, 2007
0 parents commit da069cb
Show file tree
Hide file tree
Showing 23 changed files with 2,277 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2007 Guy Naor (Famundo LLC)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
70 changes: 70 additions & 0 deletions README
@@ -0,0 +1,70 @@
= 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.

<em>NOTE:</em> 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.

== Features

* Rate any model
* Optionally add fields to the rated objects to optimize speed
* Optionally add an external rating statistics table with a record for each rated model
* Can work with the added fields, external table or just using direct SQL count/avg calls
* Use any model as the rater (defaults to User)
* Limit the range of the ratings
* Average, total and number of ratings
* Find objects by ratings or rating ranges
* Find objects by rater
* Extensively tested

== Basic Details

Install

* script/plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated
* gem install - <b>comming soon</b>

Rubyforge project

* http://rubyforge.org/projects/acts-as-rated

RDocs

* http://acts-as-rated.rubyforge.org

Subversion

* svn://rubyforge.org/var/svn/acts-as-rated

My blog with some comments about the plugin

* http://devblog.famundo.com

Work done as part of Famundo development

* http://www.famundo.com

Contact me at

* guy.naor@famundo.com

== TODO
* Test with more databases
* Test with other versions of Rails (tested against 1.2.1)
* Add view helpers for easy display and entering of the ratings


== 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

190 changes: 190 additions & 0 deletions Rakefile
@@ -0,0 +1,190 @@
require 'rubygems'

Gem::manage_gems

require 'rake/rdoctask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/testtask'
require 'rake/contrib/rubyforgepublisher'

PKG_NAME = 'acts_as_rated'
PKG_VERSION = '0.2.0'
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
PROD_HOST = "guy.naor@famundo.com"
RUBY_FORGE_PROJECT = 'acts-as-rated'
RUBY_FORGE_USER = 'guynaor'

desc 'Default: run all tests.'
task :default => :test

task :test => [:test_plugin, :test_migrations ]

desc 'Test the acts_as_rated plugin.'
Rake::TestTask.new(:test_plugin) do |t|
t.libs << 'lib'
t.pattern = 'test/rated_test.rb'
t.verbose = true
end

desc 'Test the acts_as_rated plugin.'
Rake::TestTask.new(:test_migrations) do |t|
t.libs << 'lib'
t.pattern = 'test/migration_test.rb'
t.verbose = true
end

desc 'Generate documentation for the acts_as_rated plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "#{PKG_NAME} -- Rating system for ActiveRecord models"
rdoc.options << '--line-numbers'
rdoc.options << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end

spec = Gem::Specification.new do |s|
s.name = PKG_NAME
s.version = PKG_VERSION
s.platform = Gem::Platform::RUBY
s.summary = "Rating system for active record models"
s.files = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE)
s.files.delete "test/debug.log"
s.require_path = 'lib'
s.autorequire = 'acts_as_versioned'
s.has_rdoc = true
s.test_files = Dir['test/**/*_test.rb']
s.add_dependency 'activerecord', '>= 1.10.1'
s.add_dependency 'activesupport', '>= 1.1.1'
s.author = "Guy Naor"
s.email = "guy.naor@famundo.com"
s.homepage = "http://devblog.famundo.com"
end

Rake::GemPackageTask.new(spec) do |pkg|
pkg.need_tar = true
end

desc "Publish the API documentation"
task :pdoc => [:rdoc] do
Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload
end

desc 'Publish the gem and API docs'
task :publish => [:pdoc, :rubyforge_upload]

desc "Publish the release files to RubyForge."
task :rubyforge_upload => :package do
files = %w(gem tgz).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }

if RUBY_FORGE_PROJECT then
require 'net/http'
require 'open-uri'

project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
project_data = open(project_uri) { |data| data.read }
group_id = project_data[/[?&]group_id=(\d+)/, 1]
raise "Couldn't get group id" unless group_id

# This echos password to shell which is a bit sucky
if ENV["RUBY_FORGE_PASSWORD"]
password = ENV["RUBY_FORGE_PASSWORD"]
else
print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
password = STDIN.gets.chomp
end

login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
data = [
"login=1",
"form_loginname=#{RUBY_FORGE_USER}",
"form_pw=#{password}"
].join("&")
http.post("/account/login.php", data)
end

cookie = login_response["set-cookie"]
raise "Login failed" unless cookie
headers = { "Cookie" => cookie }

release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
release_data = open(release_uri, headers) { |data| data.read }
package_id = release_data[/[?&]package_id=(\d+)/, 1]
raise "Couldn't get package id" unless package_id

first_file = true
release_id = ""

files.each do |filename|
basename = File.basename(filename)
file_ext = File.extname(filename)
file_data = File.open(filename, "rb") { |file| file.read }

puts "Releasing #{basename}..."

release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
release_date = Time.now.strftime("%Y-%m-%d %H:%M")
type_map = {
".zip" => "3000",
".tgz" => "3110",
".gz" => "3110",
".gem" => "1400"
}; type_map.default = "9999"
type = type_map[file_ext]
boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"

query_hash = if first_file then
{
"group_id" => group_id,
"package_id" => package_id,
"release_name" => PKG_FILE_NAME,
"release_date" => release_date,
"type_id" => type,
"processor_id" => "8000", # Any
"release_notes" => "",
"release_changes" => "",
"preformatted" => "1",
"submit" => "1"
}
else
{
"group_id" => group_id,
"release_id" => release_id,
"package_id" => package_id,
"step2" => "1",
"type_id" => type,
"processor_id" => "8000", # Any
"submit" => "Add This File"
}
end

query = "?" + query_hash.map do |(name, value)|
[name, URI.encode(value)].join("=")
end.join("&")

data = [
"--" + boundary,
"Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
"Content-Type: application/octet-stream",
"Content-Transfer-Encoding: binary",
"", file_data, ""
].join("\x0D\x0A")

release_headers = headers.merge(
"Content-Type" => "multipart/form-data; boundary=#{boundary}"
)

target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
http.post(target + query, data, release_headers)
end

if first_file then
release_id = release_response.body[/release_id=(\d+)/, 1]
raise("Couldn't get release id") unless release_id
end

first_file = false
end
end
end
3 changes: 3 additions & 0 deletions init.rb
@@ -0,0 +1,3 @@
require 'acts_as_rated'


1 comment on commit da069cb

@jdevine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 152 of lib/acts_as_rated.rb should read:

return ((rating_statistic.rating_avg || 0) rescue 0) if acts_as_rated_options[:stats_class]

Please sign in to comment.