recommendable 1.1.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/lib/recommendable.rb +38 -26
  2. data/lib/recommendable/configuration.rb +47 -0
  3. data/lib/recommendable/helpers.rb +3 -9
  4. data/lib/recommendable/helpers/calculations.rb +150 -0
  5. data/lib/recommendable/helpers/queriers.rb +23 -0
  6. data/lib/recommendable/helpers/redis_key_mapper.rb +29 -0
  7. data/lib/recommendable/orm/active_record.rb +6 -0
  8. data/lib/recommendable/orm/data_mapper.rb +7 -0
  9. data/lib/recommendable/orm/mongo_mapper.rb +8 -0
  10. data/lib/recommendable/orm/mongoid.rb +7 -0
  11. data/lib/recommendable/ratable.rb +83 -0
  12. data/lib/recommendable/ratable/dislikable.rb +26 -0
  13. data/lib/recommendable/ratable/likable.rb +26 -0
  14. data/lib/recommendable/rater.rb +109 -0
  15. data/lib/recommendable/rater/bookmarker.rb +120 -0
  16. data/lib/recommendable/rater/disliker.rb +122 -0
  17. data/lib/recommendable/rater/hider.rb +120 -0
  18. data/lib/recommendable/rater/liker.rb +122 -0
  19. data/lib/recommendable/rater/recommender.rb +68 -0
  20. data/lib/recommendable/version.rb +5 -4
  21. data/lib/recommendable/workers/delayed_job.rb +16 -0
  22. data/lib/recommendable/workers/rails.rb +16 -0
  23. data/lib/recommendable/workers/resque.rb +13 -0
  24. data/lib/recommendable/workers/sidekiq.rb +13 -0
  25. metadata +62 -131
  26. data/.gitignore +0 -57
  27. data/.travis.yml +0 -3
  28. data/CHANGELOG.markdown +0 -159
  29. data/Gemfile +0 -3
  30. data/Gemfile.lock +0 -112
  31. data/LICENSE.txt +0 -22
  32. data/README.markdown +0 -135
  33. data/Rakefile +0 -26
  34. data/TODO +0 -7
  35. data/app/models/recommendable/dislike.rb +0 -19
  36. data/app/models/recommendable/ignore.rb +0 -19
  37. data/app/models/recommendable/like.rb +0 -19
  38. data/app/models/recommendable/stash.rb +0 -19
  39. data/app/workers/recommendable/delayed_job_worker.rb +0 -17
  40. data/app/workers/recommendable/rails_worker.rb +0 -17
  41. data/app/workers/recommendable/resque_worker.rb +0 -14
  42. data/app/workers/recommendable/sidekiq_worker.rb +0 -14
  43. data/config/routes.rb +0 -3
  44. data/db/migrate/20120124193723_create_likes.rb +0 -17
  45. data/db/migrate/20120124193728_create_dislikes.rb +0 -17
  46. data/db/migrate/20120127092558_create_ignores.rb +0 -17
  47. data/db/migrate/20120131173909_create_stashes.rb +0 -17
  48. data/lib/generators/recommendable/USAGE +0 -8
  49. data/lib/generators/recommendable/install_generator.rb +0 -40
  50. data/lib/generators/recommendable/templates/initializer.rb +0 -28
  51. data/lib/recommendable/acts_as_recommendable.rb +0 -176
  52. data/lib/recommendable/acts_as_recommended_to.rb +0 -774
  53. data/lib/recommendable/engine.rb +0 -14
  54. data/lib/recommendable/exceptions.rb +0 -4
  55. data/lib/recommendable/railtie.rb +0 -6
  56. data/lib/sidekiq/middleware/client/unique_jobs.rb +0 -37
  57. data/lib/sidekiq/middleware/server/unique_jobs.rb +0 -17
  58. data/lib/tasks/recommendable_tasks.rake +0 -1
  59. data/recommendable.gemspec +0 -30
  60. data/script/rails +0 -8
  61. data/spec/configuration_spec.rb +0 -9
  62. data/spec/dummy/README.rdoc +0 -261
  63. data/spec/dummy/Rakefile +0 -7
  64. data/spec/dummy/app/assets/javascripts/application.js +0 -15
  65. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  66. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  67. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  68. data/spec/dummy/app/mailers/.gitkeep +0 -0
  69. data/spec/dummy/app/models/.gitkeep +0 -0
  70. data/spec/dummy/app/models/bully.rb +0 -2
  71. data/spec/dummy/app/models/movie.rb +0 -2
  72. data/spec/dummy/app/models/php_framework.rb +0 -2
  73. data/spec/dummy/app/models/user.rb +0 -3
  74. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  75. data/spec/dummy/config.ru +0 -4
  76. data/spec/dummy/config/application.rb +0 -56
  77. data/spec/dummy/config/boot.rb +0 -10
  78. data/spec/dummy/config/database.yml +0 -25
  79. data/spec/dummy/config/environment.rb +0 -5
  80. data/spec/dummy/config/environments/development.rb +0 -37
  81. data/spec/dummy/config/environments/production.rb +0 -67
  82. data/spec/dummy/config/environments/test.rb +0 -37
  83. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  84. data/spec/dummy/config/initializers/inflections.rb +0 -15
  85. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  86. data/spec/dummy/config/initializers/recommendable.rb +0 -14
  87. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  88. data/spec/dummy/config/initializers/session_store.rb +0 -8
  89. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  90. data/spec/dummy/config/locales/en.yml +0 -5
  91. data/spec/dummy/config/routes.rb +0 -4
  92. data/spec/dummy/db/migrate/20120128005553_create_likes.recommendable.rb +0 -18
  93. data/spec/dummy/db/migrate/20120128005554_create_dislikes.recommendable.rb +0 -18
  94. data/spec/dummy/db/migrate/20120128005555_create_ignores.recommendable.rb +0 -18
  95. data/spec/dummy/db/migrate/20120128020228_create_users.rb +0 -9
  96. data/spec/dummy/db/migrate/20120128020413_create_movies.rb +0 -10
  97. data/spec/dummy/db/migrate/20120128024632_create_php_frameworks.rb +0 -9
  98. data/spec/dummy/db/migrate/20120128024804_create_bullies.rb +0 -9
  99. data/spec/dummy/db/migrate/20120131195416_create_stashes.recommendable.rb +0 -19
  100. data/spec/dummy/db/schema.rb +0 -89
  101. data/spec/dummy/lib/assets/.gitkeep +0 -0
  102. data/spec/dummy/log/.gitkeep +0 -0
  103. data/spec/dummy/public/404.html +0 -26
  104. data/spec/dummy/public/422.html +0 -26
  105. data/spec/dummy/public/500.html +0 -25
  106. data/spec/dummy/public/favicon.ico +0 -0
  107. data/spec/dummy/recommendable_dummy_development +0 -0
  108. data/spec/dummy/recommendable_dummy_test +0 -0
  109. data/spec/dummy/script/rails +0 -6
  110. data/spec/factories.rb +0 -16
  111. data/spec/models/dislike_spec.rb +0 -41
  112. data/spec/models/ignore_spec.rb +0 -27
  113. data/spec/models/like_spec.rb +0 -42
  114. data/spec/models/movie_spec.rb +0 -82
  115. data/spec/models/stash_spec.rb +0 -27
  116. data/spec/models/user_benchmark_spec.rb +0 -49
  117. data/spec/models/user_spec.rb +0 -443
  118. data/spec/spec_helper.rb +0 -28
@@ -1,10 +0,0 @@
1
- class CreateMovies < ActiveRecord::Migration
2
- def change
3
- create_table :movies do |t|
4
- t.string :title
5
- t.integer :year
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- class CreatePhpFrameworks < ActiveRecord::Migration
2
- def change
3
- create_table :php_frameworks do |t|
4
- t.string :name
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class CreateBullies < ActiveRecord::Migration
2
- def change
3
- create_table :bullies do |t|
4
- t.string :username
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,19 +0,0 @@
1
- # This migration comes from recommendable (originally 20120131173909)
2
- class CreateStashes < ActiveRecord::Migration
3
- def up
4
- create_table :recommendable_stashes do |t|
5
- t.references :user
6
- t.references :stashable, :polymorphic => true
7
- t.timestamps
8
- end
9
-
10
- add_index :recommendable_stashes, :stashable_id
11
- add_index :recommendable_stashes, :stashable_type
12
- add_index :recommendable_stashes, [:user_id, :stashable_id, :stashable_type], :unique => true, :name => "user_stashed_constraint"
13
- end
14
-
15
- def down
16
- drop_table :recommendable_stashes
17
- end
18
- end
19
-
@@ -1,89 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20120131195416) do
15
-
16
- create_table "bullies", :force => true do |t|
17
- t.string "username"
18
- t.datetime "created_at", :null => false
19
- t.datetime "updated_at", :null => false
20
- end
21
-
22
- create_table "movies", :force => true do |t|
23
- t.string "title"
24
- t.integer "year"
25
- t.datetime "created_at", :null => false
26
- t.datetime "updated_at", :null => false
27
- end
28
-
29
- create_table "php_frameworks", :force => true do |t|
30
- t.string "name"
31
- t.datetime "created_at", :null => false
32
- t.datetime "updated_at", :null => false
33
- end
34
-
35
- create_table "recommendable_dislikes", :force => true do |t|
36
- t.integer "user_id"
37
- t.integer "dislikeable_id"
38
- t.string "dislikeable_type"
39
- t.datetime "created_at", :null => false
40
- t.datetime "updated_at", :null => false
41
- end
42
-
43
- add_index "recommendable_dislikes", ["dislikeable_id"], :name => "index_recommendable_dislikes_on_dislikeable_id"
44
- add_index "recommendable_dislikes", ["dislikeable_type"], :name => "index_recommendable_dislikes_on_dislikeable_type"
45
- add_index "recommendable_dislikes", ["user_id", "dislikeable_id", "dislikeable_type"], :name => "user_dislike_constraint", :unique => true
46
-
47
- create_table "recommendable_ignores", :force => true do |t|
48
- t.integer "user_id"
49
- t.integer "ignorable_id"
50
- t.string "ignorable_type"
51
- t.datetime "created_at", :null => false
52
- t.datetime "updated_at", :null => false
53
- end
54
-
55
- add_index "recommendable_ignores", ["ignorable_id"], :name => "index_recommendable_ignores_on_ignorable_id"
56
- add_index "recommendable_ignores", ["ignorable_type"], :name => "index_recommendable_ignores_on_ignorable_type"
57
- add_index "recommendable_ignores", ["user_id", "ignorable_id", "ignorable_type"], :name => "user_ignore_constraint", :unique => true
58
-
59
- create_table "recommendable_likes", :force => true do |t|
60
- t.integer "user_id"
61
- t.integer "likeable_id"
62
- t.string "likeable_type"
63
- t.datetime "created_at", :null => false
64
- t.datetime "updated_at", :null => false
65
- end
66
-
67
- add_index "recommendable_likes", ["likeable_id"], :name => "index_recommendable_likes_on_likeable_id"
68
- add_index "recommendable_likes", ["likeable_type"], :name => "index_recommendable_likes_on_likeable_type"
69
- add_index "recommendable_likes", ["user_id", "likeable_id", "likeable_type"], :name => "user_like_constraint", :unique => true
70
-
71
- create_table "recommendable_stashes", :force => true do |t|
72
- t.integer "user_id"
73
- t.integer "stashable_id"
74
- t.string "stashable_type"
75
- t.datetime "created_at", :null => false
76
- t.datetime "updated_at", :null => false
77
- end
78
-
79
- add_index "recommendable_stashes", ["stashable_id"], :name => "index_recommendable_stashes_on_stashable_id"
80
- add_index "recommendable_stashes", ["stashable_type"], :name => "index_recommendable_stashes_on_stashable_type"
81
- add_index "recommendable_stashes", ["user_id", "stashable_id", "stashable_type"], :name => "user_stashed_constraint", :unique => true
82
-
83
- create_table "users", :force => true do |t|
84
- t.string "username"
85
- t.datetime "created_at", :null => false
86
- t.datetime "updated_at", :null => false
87
- end
88
-
89
- end
File without changes
File without changes
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,25 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- </div>
24
- </body>
25
- </html>
File without changes
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,16 +0,0 @@
1
- Factory.define :user do |f|
2
- f.username "test_user_%d"
3
- end
4
-
5
- Factory.define :movie do |f|
6
- f.title "test_movie_%d"
7
- f.year 2001
8
- end
9
-
10
- Factory.define :bully do |f|
11
- f.username "bad_user_%d"
12
- end
13
-
14
- Factory.define :php_framework do |f|
15
- f.name "CakePHP"
16
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class DislikeSpec < MiniTest::Spec
4
- describe Recommendable::Dislike do
5
- before :each do
6
- @user = User.create(:username => "dave")
7
- end
8
-
9
- it "should not be created for an object that does not act_as_recommendedable" do
10
- django = PhpFramework.create(:name => "django")
11
- proc { @user.dislike(django) }.must_raise Recommendable::UnrecommendableError
12
- end
13
-
14
- it "should be created for an object that does act_as_recommendable" do
15
- movie = Movie.create(:title => "Star Wars: Episode I - The Phantom Menace", :year => 1999)
16
- @user.dislike(movie).must_equal true
17
- end
18
-
19
- it "should not be created twice for the same user-object pair" do
20
- movie = Movie.create(:title => "Star Wars: Episode I - The Phantom Menace", :year => 1999)
21
-
22
- @user.dislike(movie).must_equal true
23
- @user.dislike(movie).must_be_nil
24
- Recommendable::Dislike.count.must_equal 1
25
- end
26
-
27
- it "should cache the number of dislikes" do
28
- movie = Movie.create(:title => "Star Wars: Episode I - The Phantom Menace", :year => 1999)
29
- @user2 = User.create(:username => "frank")
30
-
31
- @user.dislike(movie)
32
- movie.dislike_count.must_equal 1
33
-
34
- @user2.dislike(movie)
35
- movie.dislike_count.must_equal 2
36
-
37
- @user.undislike(movie)
38
- movie.dislike_count.must_equal 1
39
- end
40
- end
41
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class IgnoreSpec < MiniTest::Spec
4
- describe Recommendable::Ignore do
5
- before :each do
6
- @user = User.create(:username => "dave")
7
- end
8
-
9
- it "should not be created for an object that does not act_as_recommendedable" do
10
- web2py = PhpFramework.create(:name => "web2py")
11
- proc { @user.ignore(web2py) }.must_raise Recommendable::UnrecommendableError
12
- end
13
-
14
- it "should be created for an object that does act_as_recommendable" do
15
- movie = Movie.create(:title => "Star Wars: Episode I - The Phantom Menace", :year => 1999)
16
- @user.ignore(movie).must_equal true
17
- end
18
-
19
- it "should not be created twice for the same user-object pair" do
20
- movie = Movie.create(:title => "Star Wars: Episode I - The Phantom Menace", :year => 1999)
21
-
22
- @user.ignore(movie).must_equal true
23
- @user.ignore(movie).must_be_nil
24
- Recommendable::Ignore.count.must_equal 1
25
- end
26
- end
27
- end
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class LikeSpec < MiniTest::Spec
4
- describe Recommendable::Like do
5
- before :each do
6
- @user = User.create(:username => "dave")
7
- end
8
-
9
- it "should not be created for an object that does not act_as_recommendedable" do
10
- cake = PhpFramework.create(:name => "CakePHP")
11
- proc { @user.like(cake) }.must_raise Recommendable::UnrecommendableError
12
- end
13
-
14
- it "should be created for an object that does act_as_recommendable" do
15
- movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
16
-
17
- @user.like(movie).must_equal true
18
- end
19
-
20
- it "should not be created twice for the same user-object pair" do
21
- movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
22
-
23
- @user.like(movie).must_equal true
24
- @user.like(movie).must_be_nil
25
- Recommendable::Like.count.must_equal 1
26
- end
27
-
28
- it "should cache the number of likes" do
29
- movie = Movie.create(:title => "2001: A Space Odyssey", :year => 1968)
30
- @user2 = User.create(:username => "frank")
31
-
32
- @user.like(movie)
33
- movie.like_count.must_equal 1
34
-
35
- @user2.like(movie)
36
- movie.like_count.must_equal 2
37
-
38
- @user.unlike(movie)
39
- movie.like_count.must_equal 1
40
- end
41
- end
42
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class MovieSpec < MiniTest::Spec
4
- describe Movie do
5
- describe "before_destroy filters" do
6
- before :each do
7
- Recommendable.redis.flushdb
8
-
9
- @user1 = Factory(:user)
10
-
11
- @movie1 = Factory(:movie)
12
- @movie2 = Factory(:movie)
13
- end
14
-
15
- it "should be removed from scores" do
16
- @user1.like @movie1
17
- @user1.like @movie2
18
-
19
- @movie2.destroy
20
-
21
- Movie.top(2).wont_include @movie2
22
- end
23
-
24
- it "should be removed from recommendations" do
25
- @user2 = Factory(:user)
26
- @user1.like @movie1
27
- @user2.like @movie1
28
- @user2.like @movie2
29
-
30
- @user1.send :update_recommendations
31
- @movie2.destroy
32
-
33
- @user2.liked.size.must_equal 1
34
- @user1.recommendations.size.must_equal 0
35
- end
36
- end
37
-
38
- describe ".top" do
39
- before :each do
40
- Recommendable.redis.flushdb
41
-
42
- @user1 = Factory(:user)
43
- @user2 = Factory(:user)
44
- @user3 = Factory(:user)
45
- @user4 = Factory(:user)
46
- @user5 = Factory(:user)
47
-
48
- @movie1 = Factory(:movie)
49
- @movie2 = Factory(:movie)
50
- @movie3 = Factory(:movie)
51
- @movie4 = Factory(:movie)
52
- @movie5 = Factory(:movie)
53
- end
54
-
55
- it "should sort movies accordingly" do
56
- movies = Movie.all
57
-
58
- movies.each { |m| @user1.like m }
59
- movies.pop
60
- movies.each { |m| @user2.like m }
61
- movies.pop
62
- movies.each { |m| @user3.like m }
63
- movies.pop
64
- movies.each { |m| @user4.dislike m }
65
-
66
- @user5.dislike @movie1
67
- @user5.dislike @movie2
68
- @user5.dislike @movie3
69
- @user5.like @movie4
70
- @user5.like @movie5
71
-
72
- top_movies = Movie.top(5)
73
-
74
- top_movies[0].must_equal @movie4
75
- top_movies[1].must_equal @movie5
76
- top_movies[2].must_equal @movie3
77
- top_movies[3].must_equal @movie2
78
- top_movies[4].must_equal @movie1
79
- end
80
- end
81
- end
82
- end