socialization-cassandra 0.0.1.pre.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +7 -0
  4. data/CHANGELOG.md +0 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +144 -0
  8. data/Rakefile +10 -0
  9. data/init.rb +1 -0
  10. data/lib/generators/socialization/socialization_generator.rb +17 -0
  11. data/lib/generators/socialization/templates/cassandra/model_comment.rb +2 -0
  12. data/lib/generators/socialization/templates/cassandra/model_follow.rb +2 -0
  13. data/lib/generators/socialization/templates/cassandra/model_like.rb +2 -0
  14. data/lib/generators/socialization/templates/cassandra/model_share.rb +2 -0
  15. data/lib/generators/socialization/templates/socialization_cassandra_migrations.rake +141 -0
  16. data/lib/socialization/actors/commenter.rb +79 -0
  17. data/lib/socialization/actors/follower.rb +79 -0
  18. data/lib/socialization/actors/liker.rb +79 -0
  19. data/lib/socialization/actors/mentioner.rb +79 -0
  20. data/lib/socialization/actors/sharer.rb +79 -0
  21. data/lib/socialization/config/config.rb +51 -0
  22. data/lib/socialization/helpers/acts_as_helpers.rb +49 -0
  23. data/lib/socialization/helpers/string.rb +17 -0
  24. data/lib/socialization/lib/exceptions.rb +3 -0
  25. data/lib/socialization/stores/cassandra/base.rb +149 -0
  26. data/lib/socialization/stores/cassandra/comment.rb +28 -0
  27. data/lib/socialization/stores/cassandra/config.rb +29 -0
  28. data/lib/socialization/stores/cassandra/follow.rb +36 -0
  29. data/lib/socialization/stores/cassandra/like.rb +35 -0
  30. data/lib/socialization/stores/cassandra/mixins/base.rb +8 -0
  31. data/lib/socialization/stores/cassandra/share.rb +28 -0
  32. data/lib/socialization/stores/mixins/base.rb +22 -0
  33. data/lib/socialization/stores/mixins/follow.rb +39 -0
  34. data/lib/socialization/stores/mixins/like.rb +40 -0
  35. data/lib/socialization/stores/mixins/mention.rb +40 -0
  36. data/lib/socialization/version.rb +3 -0
  37. data/lib/socialization/victims/commentable.rb +51 -0
  38. data/lib/socialization/victims/followable.rb +50 -0
  39. data/lib/socialization/victims/likeable.rb +51 -0
  40. data/lib/socialization/victims/shareable.rb +51 -0
  41. data/lib/socialization.rb +17 -0
  42. data/socialization-cassandra.gemspec +30 -0
  43. data/test/actors/follower_test.rb +129 -0
  44. data/test/actors/liker_test.rb +121 -0
  45. data/test/stores/cassandra/base_test.rb +186 -0
  46. data/test/stores/cassandra/config_test.rb +36 -0
  47. data/test/stores/cassandra/follow_store_test.rb +28 -0
  48. data/test/stores/cassandra/like_store_test.rb +26 -0
  49. data/test/string_test.rb +13 -0
  50. data/test/test_helper.rb +259 -0
  51. data/test/victims/followable_test.rb +65 -0
  52. data/test/victims/likeable_test.rb +67 -0
  53. data/test/world_test.rb +107 -0
  54. metadata +209 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa470f9302a13641ec885b36e01fd7fc4f99b1e3
4
+ data.tar.gz: e236cad8edaa6d361a2bab6fa813b86f06fc19af
5
+ SHA512:
6
+ metadata.gz: 1bb3d0d4e8e2dde12d7f76f260dfed526bb8c6bfcb279f9218fcaaa2619dba0752a93a2a65f4cc4d8464e66510fc77e15ba31df213e7fd3febd046bc7240d973
7
+ data.tar.gz: 3aa917f4743fc690e0b8cc5e6fe452077e123ca41528ef6e7e6a1c40a568471aa262799cb05aeb4bb4eb1d9465c0c943df9e7a9d5830b1a34f2a2e82873a4004
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ test/debug.log
3
+ coverage
4
+ rdoc
5
+ memory
6
+ *.gem
7
+ .rvmrc
8
+ Gemfile.lock
9
+ log
10
+ doc
11
+ .yardoc
12
+ .rbenv-version
13
+ gemfiles
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+
7
+ script: bundle exec rake test
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+ gem 'activerecord'
3
+ gem 'cassandra-driver'
4
+ gem 'logger'
5
+ gem 'mocha'
6
+ gem 'shoulda'
7
+ gem 'sqlite3'
8
+ gem 'yard'
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Amrit Singh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Socialization-Cassandra
2
+
3
+ Socialization is a Ruby Gem that allows any ActiveRecord model to `Follow`, `Like`, 'Comment' and/or `Share` any other model. Cassandra is used as a data store.
4
+
5
+ ## Installation
6
+
7
+ ### Rails 3/4
8
+
9
+ Add the gem to the gemfile:
10
+ `gem "socialization-cassandra"`
11
+
12
+ Run the generator:
13
+ `rails generate socialization -s`
14
+
15
+ Run:
16
+ `rake socialization:migrate`
17
+
18
+ ### Rails 2.3.x Support
19
+
20
+ This gem requires Rails 3 or better. Sorry!
21
+
22
+ ## Usage
23
+
24
+ ### Setup
25
+
26
+ Allow a model to be followed:
27
+
28
+ class Celebrity < ActiveRecord::Base
29
+ ...
30
+ acts_as_followable
31
+ ...
32
+ end
33
+
34
+ Allow a model to be a follower:
35
+
36
+ class User < ActiveRecord::Base
37
+ ...
38
+ acts_as_follower
39
+ ...
40
+ end
41
+
42
+
43
+ Allow a model to be liked:
44
+
45
+ class Movie < ActiveRecord::Base
46
+ ...
47
+ acts_as_likeable
48
+ ...
49
+ end
50
+
51
+ Allow a model to like:
52
+
53
+ class User < ActiveRecord::Base
54
+ ...
55
+ acts_as_liker
56
+ ...
57
+ end
58
+
59
+ ***
60
+
61
+
62
+ ### acts_as_follower Methods
63
+
64
+ Follow something
65
+
66
+ user.follow!(celebrity)
67
+
68
+ Stop following
69
+
70
+ user.unfollow!(celebrity)
71
+
72
+ Toggle
73
+
74
+ user.toggle_follow!(celebrity)
75
+
76
+ Is following?
77
+
78
+ user.follows?(celebrity)
79
+
80
+ What items are you following (given that an Item model is followed)?
81
+
82
+ user.followees(Item)
83
+
84
+
85
+ ***
86
+
87
+
88
+ ### acts_as_followable Methods
89
+
90
+ Find out if an objects follows
91
+
92
+ celebrity.followed_by?(user)
93
+
94
+ All followers
95
+
96
+ celebrity.followers(User)
97
+
98
+
99
+ ***
100
+
101
+
102
+ ### acts_as_liker Methods
103
+
104
+ Like something
105
+
106
+ user.like!(movie)
107
+
108
+ Stop liking
109
+
110
+ user.unlike!(movie)
111
+
112
+ Toggle
113
+
114
+ user.toggle_like!(celebrity)
115
+
116
+ Likes?
117
+
118
+ user.likes?(movie)
119
+
120
+ ***
121
+
122
+
123
+ ### acts_as_likeable Methods
124
+
125
+ Find out if an objects likes
126
+
127
+ movie.liked_by?(user)
128
+
129
+ All likers
130
+
131
+ movie.likers(User)
132
+
133
+ ***
134
+
135
+ ## Note on Patches/Pull Requests
136
+
137
+ * Fork the project.
138
+ * Make your feature addition or bug fix.
139
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
140
+ * Send me a pull request. Bonus points for topic branches.
141
+
142
+ ## Copyright
143
+
144
+ Copyright (c) 2015-2016 Amrit Singh-- Released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
4
+
5
+ desc 'Test the socialization plugin.'
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = true
10
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'socialization'
@@ -0,0 +1,17 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ class SocializationGenerator < Rails::Generators::Base
5
+ include Rails::Generators::Migration
6
+ source_root File.expand_path(File.join('templates'), File.dirname(__FILE__))
7
+
8
+ def create_migration_file
9
+ copy_file "cassandra/model_follow.rb", 'app/models/follow.rb'
10
+ copy_file "cassandra/model_like.rb", 'app/models/like.rb'
11
+ copy_file "cassandra/model_comment.rb", 'app/models/comment.rb'
12
+ copy_file "cassandra/model_share.rb", 'app/models/share.rb'
13
+
14
+ migration_template 'socialization_cassandra_migrations.rake', 'lib/tasks/socialization_cassandra_migrations.rake'
15
+
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ class Comment < Socialization::CassandraStores::Comment
2
+ end
@@ -0,0 +1,2 @@
1
+ class Follow < Socialization::CassandraStores::Follow
2
+ end
@@ -0,0 +1,2 @@
1
+ class Like < Socialization::CassandraStores::Like
2
+ end
@@ -0,0 +1,2 @@
1
+ class Share < Socialization::CassandraStores::Share
2
+ end
@@ -0,0 +1,141 @@
1
+ class SocializationCassandraMigrations
2
+
3
+ MIGRATIONS = [
4
+
5
+ # likes
6
+
7
+ "CREATE TABLE likes (
8
+ actor_type varchar,
9
+ actor_id bigint,
10
+ victim_id bigint,
11
+ victim_type varchar,
12
+ created_at bigint,
13
+ PRIMARY KEY ((actor_type, actor_id), created_at)
14
+ );",
15
+
16
+ "CREATE INDEX ON likes (victim_type)",
17
+ "CREATE INDEX ON likes (victim_id)",
18
+
19
+ "CREATE TABLE likers (
20
+ actor_type varchar,
21
+ actor_id bigint,
22
+ victim_id bigint,
23
+ victim_type varchar,
24
+ created_at bigint,
25
+ PRIMARY KEY ((victim_type, victim_id), created_at)
26
+ );",
27
+
28
+ "CREATE INDEX ON likers (actor_type)",
29
+ "CREATE INDEX ON likers (actor_id)",
30
+
31
+ "CREATE TABLE liker_counter (
32
+ victim_id bigint,
33
+ victim_type varchar,
34
+ cnt counter,
35
+ PRIMARY KEY (victim_type, victim_id)
36
+ );",
37
+
38
+ # follow
39
+
40
+ "CREATE TABLE followings (
41
+ actor_type varchar,
42
+ actor_id bigint,
43
+ victim_id bigint,
44
+ victim_type varchar,
45
+ created_at bigint,
46
+ PRIMARY KEY ((actor_type, actor_id), created_at)
47
+ );",
48
+
49
+ "CREATE INDEX ON followings (victim_type)",
50
+ "CREATE INDEX ON followings (victim_id)",
51
+
52
+ "CREATE TABLE followers (
53
+ actor_type varchar,
54
+ actor_id bigint,
55
+ victim_id bigint,
56
+ victim_type varchar,
57
+ created_at bigint,
58
+ PRIMARY KEY ((victim_type, victim_id), created_at)
59
+ );",
60
+
61
+ "CREATE INDEX ON followers (actor_type)",
62
+ "CREATE INDEX ON followers (actor_id)",
63
+
64
+ "CREATE TABLE following_counter (
65
+ actor_id bigint,
66
+ actor_type varchar,
67
+ cnt counter,
68
+ PRIMARY KEY (actor_type, actor_id)
69
+ );",
70
+
71
+ "CREATE TABLE follower_counter (
72
+ victim_id bigint,
73
+ victim_type varchar,
74
+ cnt counter,
75
+ PRIMARY KEY (victim_type, victim_id)
76
+ );",
77
+
78
+ # Comments
79
+
80
+ "CREATE TABLE comments (
81
+ actor_type varchar,
82
+ actor_id bigint,
83
+ victim_id bigint,
84
+ victim_type varchar,
85
+ created_at bigint,
86
+ txt text,
87
+ PRIMARY KEY ((victim_type, victim_id), created_at)
88
+ );",
89
+
90
+ "CREATE TABLE comment_counter (
91
+ victim_id bigint,
92
+ victim_type varchar,
93
+ cnt counter,
94
+ PRIMARY KEY (victim_type, victim_id)
95
+ );",
96
+
97
+ # Share
98
+
99
+ "CREATE TABLE shares (
100
+ actor_type varchar,
101
+ actor_id bigint,
102
+ victim_id bigint,
103
+ victim_type varchar,
104
+ networks set<text>,
105
+ created_at bigint,
106
+ txt text,
107
+ PRIMARY KEY ((victim_type, victim_id), created_at)
108
+ );",
109
+
110
+ "CREATE TABLE share_counter (
111
+ victim_id bigint,
112
+ victim_type varchar,
113
+ cnt counter,
114
+ PRIMARY KEY (victim_type, victim_id)
115
+ );"
116
+
117
+ ]
118
+
119
+ end
120
+
121
+
122
+ namespace :socialization do
123
+ desc "Socialization Cassandra Migrations"
124
+ task(:migrate => :environment) do
125
+ begin
126
+ session = Socialization.cassandra.connect('system')
127
+ session.execute("CREATE KEYSPACE #{Socialization.keyspace} WITH replication = {'class': 'NetworkTopologyStrategy'}")
128
+ rescue Cassandra::Errors::AlreadyExistsError => e
129
+ next
130
+ end
131
+ session = Socialization.cassandra.connect(Socialization.keyspace)
132
+
133
+ SocializationCassandraMigrations::MIGRATIONS.each do |m|
134
+ begin
135
+ Socialization.cassandra_session.execute(m)
136
+ rescue Cassandra::Errors::AlreadyExistsError => e
137
+ next
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,79 @@
1
+ module Socialization
2
+ module Commenter
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ after_destroy { Socialization.comment_model.remove_commentables(self) }
7
+
8
+ # Specifies if self can comment {Commentable} objects.
9
+ #
10
+ # @return [Boolean]
11
+ def is_commenter?
12
+ true
13
+ end
14
+ alias commenter? is_commenter?
15
+
16
+ # Create a new {Comment comment} relationship.
17
+ #
18
+ # @param [Commentable] commentable the object to be commented.
19
+ # @return [Boolean]
20
+ def comment!(commentable)
21
+ raise Socialization::ArgumentError, "#{commentable} is not commentable!" unless commentable.respond_to?(:is_commentable?) && commentable.is_commentable?
22
+ Socialization.comment_model.comment!(self, commentable)
23
+ end
24
+
25
+ # Delete a {Comment comment} relationship.
26
+ #
27
+ # @param [Commentable] commentable the object to uncomment.
28
+ # @return [Boolean]
29
+ def uncomment!(commentable)
30
+ raise Socialization::ArgumentError, "#{commentable} is not commentable!" unless commentable.respond_to?(:is_commentable?) && commentable.is_commentable?
31
+ Socialization.comment_model.uncomment!(self, commentable)
32
+ end
33
+
34
+ # Toggles a {Comment comment} relationship.
35
+ #
36
+ # @param [Commentable] commentable the object to comment/uncomment.
37
+ # @return [Boolean]
38
+ def toggle_comment!(commentable)
39
+ raise Socialization::ArgumentError, "#{commentable} is not commentable!" unless commentable.respond_to?(:is_commentable?) && commentable.is_commentable?
40
+ if comments?(commentable)
41
+ uncomment!(commentable)
42
+ false
43
+ else
44
+ comment!(commentable)
45
+ true
46
+ end
47
+ end
48
+
49
+ # Specifies if self comments a {Commentable} object.
50
+ #
51
+ # @param [Commentable] commentable the {Commentable} object to test against.
52
+ # @return [Boolean]
53
+ def comments?(commentable)
54
+ raise Socialization::ArgumentError, "#{commentable} is not commentable!" unless commentable.respond_to?(:is_commentable?) && commentable.is_commentable?
55
+ Socialization.comment_model.comments?(self, commentable)
56
+ end
57
+
58
+ # Returns all the commentables of a certain type that are commented by self
59
+ #
60
+ # @params [Commentable] klass the type of {Commentable} you want
61
+ # @params [Hash] opts a hash of options
62
+ # @return [Array<Commentable, Numeric>] An array of Commentable objects or IDs
63
+ def commentables(klass, opts = {})
64
+ Socialization.comment_model.commentables(self, klass, opts)
65
+ end
66
+ alias :commentees :commentables
67
+
68
+ # Returns a relation for all the commentables of a certain type that are commented by self
69
+ #
70
+ # @params [Commentable] klass the type of {Commentable} you want
71
+ # @params [Hash] opts a hash of options
72
+ # @return ActiveRecord::Relation
73
+ def commentables_relation(klass, opts = {})
74
+ Socialization.comment_model.commentables_relation(self, klass, opts)
75
+ end
76
+ alias :commentees_relation :commentables_relation
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,79 @@
1
+ module Socialization
2
+ module Follower
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ after_destroy { Socialization.follow_model.remove_followables(self) }
7
+
8
+ # Specifies if self can follow {Followable} objects.
9
+ #
10
+ # @return [Boolean]
11
+ def is_follower?
12
+ true
13
+ end
14
+ alias follower? is_follower?
15
+
16
+ # Create a new {Follow follow} relationship.
17
+ #
18
+ # @param [Followable] followable the object to be followed.
19
+ # @return [Boolean]
20
+ def follow!(followable)
21
+ raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
22
+ Socialization.follow_model.follow!(self, followable)
23
+ end
24
+
25
+ # Delete a {Follow follow} relationship.
26
+ #
27
+ # @param [Followable] followable the object to unfollow.
28
+ # @return [Boolean]
29
+ def unfollow!(followable)
30
+ raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
31
+ Socialization.follow_model.unfollow!(self, followable)
32
+ end
33
+
34
+ # Toggles a {Follow follow} relationship.
35
+ #
36
+ # @param [Followable] followable the object to follow/unfollow.
37
+ # @return [Boolean]
38
+ def toggle_follow!(followable)
39
+ raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
40
+ if follows?(followable)
41
+ unfollow!(followable)
42
+ false
43
+ else
44
+ follow!(followable)
45
+ true
46
+ end
47
+ end
48
+
49
+ # Specifies if self follows a {Followable} object.
50
+ #
51
+ # @param [Followable] followable the {Followable} object to test against.
52
+ # @return [Boolean]
53
+ def follows?(followable)
54
+ raise Socialization::ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
55
+ Socialization.follow_model.follows?(self, followable)
56
+ end
57
+
58
+ # Returns all the followables of a certain type that are followed by self
59
+ #
60
+ # @params [Followable] klass the type of {Followable} you want
61
+ # @params [Hash] opts a hash of options
62
+ # @return [Array<Followable, Numeric>] An array of Followable objects or IDs
63
+ def followables(klass, opts = {})
64
+ Socialization.follow_model.followables(self, klass, opts)
65
+ end
66
+ alias :followees :followables
67
+
68
+ # Returns a relation for all the followables of a certain type that are followed by self
69
+ #
70
+ # @params [Followable] klass the type of {Followable} you want
71
+ # @params [Hash] opts a hash of options
72
+ # @return ActiveRecord::Relation
73
+ def followables_relation(klass, opts = {})
74
+ Socialization.follow_model.followables_relation(self, klass, opts)
75
+ end
76
+ alias :followees_relation :followables_relation
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,79 @@
1
+ module Socialization
2
+ module Liker
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ after_destroy { Socialization.like_model.remove_likeables(self) }
7
+
8
+ # Specifies if self can like {Likeable} objects.
9
+ #
10
+ # @return [Boolean]
11
+ def is_liker?
12
+ true
13
+ end
14
+ alias liker? is_liker?
15
+
16
+ # Create a new {Like like} relationship.
17
+ #
18
+ # @param [Likeable] likeable the object to be liked.
19
+ # @return [Boolean]
20
+ def like!(likeable)
21
+ raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
22
+ Socialization.like_model.like!(self, likeable)
23
+ end
24
+
25
+ # Delete a {Like like} relationship.
26
+ #
27
+ # @param [Likeable] likeable the object to unlike.
28
+ # @return [Boolean]
29
+ def unlike!(likeable)
30
+ raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
31
+ Socialization.like_model.unlike!(self, likeable)
32
+ end
33
+
34
+ # Toggles a {Like like} relationship.
35
+ #
36
+ # @param [Likeable] likeable the object to like/unlike.
37
+ # @return [Boolean]
38
+ def toggle_like!(likeable)
39
+ raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
40
+ if likes?(likeable)
41
+ unlike!(likeable)
42
+ false
43
+ else
44
+ like!(likeable)
45
+ true
46
+ end
47
+ end
48
+
49
+ # Specifies if self likes a {Likeable} object.
50
+ #
51
+ # @param [Likeable] likeable the {Likeable} object to test against.
52
+ # @return [Boolean]
53
+ def likes?(likeable)
54
+ raise Socialization::ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
55
+ Socialization.like_model.likes?(self, likeable)
56
+ end
57
+
58
+ # Returns all the likeables of a certain type that are liked by self
59
+ #
60
+ # @params [Likeable] klass the type of {Likeable} you want
61
+ # @params [Hash] opts a hash of options
62
+ # @return [Array<Likeable, Numeric>] An array of Likeable objects or IDs
63
+ def likeables(klass, opts = {})
64
+ Socialization.like_model.likeables(self, klass, opts)
65
+ end
66
+ alias :likees :likeables
67
+
68
+ # Returns a relation for all the likeables of a certain type that are liked by self
69
+ #
70
+ # @params [Likeable] klass the type of {Likeable} you want
71
+ # @params [Hash] opts a hash of options
72
+ # @return ActiveRecord::Relation
73
+ def likeables_relation(klass, opts = {})
74
+ Socialization.like_model.likeables_relation(self, klass, opts)
75
+ end
76
+ alias :likees_relation :likeables_relation
77
+ end
78
+ end
79
+ end