Skip to content

Commit da069cb

Browse files
author
guynaor
committed
Initial import into Rubyforge
git-svn-id: svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated@1 d2fe85f9-699c-4bcc-83cd-509c172d722e
0 parents  commit da069cb

23 files changed

+2277
-0
lines changed

MIT-LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2007 Guy Naor (Famundo LLC)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
= acts_as_rated
2+
3+
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.
4+
5+
Comes complete with the needed migrations code to make it easy to add to any project.
6+
7+
<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.
8+
9+
== Features
10+
11+
* Rate any model
12+
* Optionally add fields to the rated objects to optimize speed
13+
* Optionally add an external rating statistics table with a record for each rated model
14+
* Can work with the added fields, external table or just using direct SQL count/avg calls
15+
* Use any model as the rater (defaults to User)
16+
* Limit the range of the ratings
17+
* Average, total and number of ratings
18+
* Find objects by ratings or rating ranges
19+
* Find objects by rater
20+
* Extensively tested
21+
22+
== Basic Details
23+
24+
Install
25+
26+
* script/plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated
27+
* gem install - <b>comming soon</b>
28+
29+
Rubyforge project
30+
31+
* http://rubyforge.org/projects/acts-as-rated
32+
33+
RDocs
34+
35+
* http://acts-as-rated.rubyforge.org
36+
37+
Subversion
38+
39+
* svn://rubyforge.org/var/svn/acts-as-rated
40+
41+
My blog with some comments about the plugin
42+
43+
* http://devblog.famundo.com
44+
45+
Work done as part of Famundo development
46+
47+
* http://www.famundo.com
48+
49+
Contact me at
50+
51+
52+
53+
== TODO
54+
* Test with more databases
55+
* Test with other versions of Rails (tested against 1.2.1)
56+
* Add view helpers for easy display and entering of the ratings
57+
58+
59+
== Testing the plugin
60+
61+
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.
62+
63+
run the tests:
64+
rake test
65+
66+
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.
67+
68+
Testing defaults to postgresql, to change it set the environment variable DB to the driver you want to use:
69+
env DB='mysql' rake test
70+

Rakefile

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
require 'rubygems'
2+
3+
Gem::manage_gems
4+
5+
require 'rake/rdoctask'
6+
require 'rake/packagetask'
7+
require 'rake/gempackagetask'
8+
require 'rake/testtask'
9+
require 'rake/contrib/rubyforgepublisher'
10+
11+
PKG_NAME = 'acts_as_rated'
12+
PKG_VERSION = '0.2.0'
13+
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14+
PROD_HOST = "[email protected]"
15+
RUBY_FORGE_PROJECT = 'acts-as-rated'
16+
RUBY_FORGE_USER = 'guynaor'
17+
18+
desc 'Default: run all tests.'
19+
task :default => :test
20+
21+
task :test => [:test_plugin, :test_migrations ]
22+
23+
desc 'Test the acts_as_rated plugin.'
24+
Rake::TestTask.new(:test_plugin) do |t|
25+
t.libs << 'lib'
26+
t.pattern = 'test/rated_test.rb'
27+
t.verbose = true
28+
end
29+
30+
desc 'Test the acts_as_rated plugin.'
31+
Rake::TestTask.new(:test_migrations) do |t|
32+
t.libs << 'lib'
33+
t.pattern = 'test/migration_test.rb'
34+
t.verbose = true
35+
end
36+
37+
desc 'Generate documentation for the acts_as_rated plugin.'
38+
Rake::RDocTask.new(:rdoc) do |rdoc|
39+
rdoc.rdoc_dir = 'doc'
40+
rdoc.title = "#{PKG_NAME} -- Rating system for ActiveRecord models"
41+
rdoc.options << '--line-numbers'
42+
rdoc.options << '--inline-source'
43+
rdoc.rdoc_files.include('README')
44+
rdoc.rdoc_files.include('lib/**/*.rb')
45+
end
46+
47+
spec = Gem::Specification.new do |s|
48+
s.name = PKG_NAME
49+
s.version = PKG_VERSION
50+
s.platform = Gem::Platform::RUBY
51+
s.summary = "Rating system for active record models"
52+
s.files = FileList["{lib,test}/**/*"].to_a + %w(README MIT-LICENSE)
53+
s.files.delete "test/debug.log"
54+
s.require_path = 'lib'
55+
s.autorequire = 'acts_as_versioned'
56+
s.has_rdoc = true
57+
s.test_files = Dir['test/**/*_test.rb']
58+
s.add_dependency 'activerecord', '>= 1.10.1'
59+
s.add_dependency 'activesupport', '>= 1.1.1'
60+
s.author = "Guy Naor"
61+
s.email = "[email protected]"
62+
s.homepage = "http://devblog.famundo.com"
63+
end
64+
65+
Rake::GemPackageTask.new(spec) do |pkg|
66+
pkg.need_tar = true
67+
end
68+
69+
desc "Publish the API documentation"
70+
task :pdoc => [:rdoc] do
71+
Rake::RubyForgePublisher.new(RUBY_FORGE_PROJECT, RUBY_FORGE_USER).upload
72+
end
73+
74+
desc 'Publish the gem and API docs'
75+
task :publish => [:pdoc, :rubyforge_upload]
76+
77+
desc "Publish the release files to RubyForge."
78+
task :rubyforge_upload => :package do
79+
files = %w(gem tgz).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
80+
81+
if RUBY_FORGE_PROJECT then
82+
require 'net/http'
83+
require 'open-uri'
84+
85+
project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
86+
project_data = open(project_uri) { |data| data.read }
87+
group_id = project_data[/[?&]group_id=(\d+)/, 1]
88+
raise "Couldn't get group id" unless group_id
89+
90+
# This echos password to shell which is a bit sucky
91+
if ENV["RUBY_FORGE_PASSWORD"]
92+
password = ENV["RUBY_FORGE_PASSWORD"]
93+
else
94+
print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
95+
password = STDIN.gets.chomp
96+
end
97+
98+
login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
99+
data = [
100+
"login=1",
101+
"form_loginname=#{RUBY_FORGE_USER}",
102+
"form_pw=#{password}"
103+
].join("&")
104+
http.post("/account/login.php", data)
105+
end
106+
107+
cookie = login_response["set-cookie"]
108+
raise "Login failed" unless cookie
109+
headers = { "Cookie" => cookie }
110+
111+
release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
112+
release_data = open(release_uri, headers) { |data| data.read }
113+
package_id = release_data[/[?&]package_id=(\d+)/, 1]
114+
raise "Couldn't get package id" unless package_id
115+
116+
first_file = true
117+
release_id = ""
118+
119+
files.each do |filename|
120+
basename = File.basename(filename)
121+
file_ext = File.extname(filename)
122+
file_data = File.open(filename, "rb") { |file| file.read }
123+
124+
puts "Releasing #{basename}..."
125+
126+
release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
127+
release_date = Time.now.strftime("%Y-%m-%d %H:%M")
128+
type_map = {
129+
".zip" => "3000",
130+
".tgz" => "3110",
131+
".gz" => "3110",
132+
".gem" => "1400"
133+
}; type_map.default = "9999"
134+
type = type_map[file_ext]
135+
boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
136+
137+
query_hash = if first_file then
138+
{
139+
"group_id" => group_id,
140+
"package_id" => package_id,
141+
"release_name" => PKG_FILE_NAME,
142+
"release_date" => release_date,
143+
"type_id" => type,
144+
"processor_id" => "8000", # Any
145+
"release_notes" => "",
146+
"release_changes" => "",
147+
"preformatted" => "1",
148+
"submit" => "1"
149+
}
150+
else
151+
{
152+
"group_id" => group_id,
153+
"release_id" => release_id,
154+
"package_id" => package_id,
155+
"step2" => "1",
156+
"type_id" => type,
157+
"processor_id" => "8000", # Any
158+
"submit" => "Add This File"
159+
}
160+
end
161+
162+
query = "?" + query_hash.map do |(name, value)|
163+
[name, URI.encode(value)].join("=")
164+
end.join("&")
165+
166+
data = [
167+
"--" + boundary,
168+
"Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
169+
"Content-Type: application/octet-stream",
170+
"Content-Transfer-Encoding: binary",
171+
"", file_data, ""
172+
].join("\x0D\x0A")
173+
174+
release_headers = headers.merge(
175+
"Content-Type" => "multipart/form-data; boundary=#{boundary}"
176+
)
177+
178+
target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
179+
http.post(target + query, data, release_headers)
180+
end
181+
182+
if first_file then
183+
release_id = release_response.body[/release_id=(\d+)/, 1]
184+
raise("Couldn't get release id") unless release_id
185+
end
186+
187+
first_file = false
188+
end
189+
end
190+
end

init.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require 'acts_as_rated'
2+
3+

0 commit comments

Comments
 (0)