socialization 0.4.0 → 0.5.0.beta
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.
- data/.gitignore +5 -1
- data/CHANGELOG.md +41 -0
- data/README.md +246 -0
- data/demo/{demo_app/.gitignore → .gitignore} +0 -0
- data/demo/{demo_app/Gemfile → Gemfile} +1 -1
- data/demo/{demo_app/README.rdoc → README.rdoc} +0 -0
- data/demo/{demo_app/Rakefile → Rakefile} +0 -0
- data/demo/{demo_app/app → app}/assets/images/rails.png +0 -0
- data/demo/{demo_app/app → app}/assets/javascripts/application.js +0 -0
- data/demo/{demo_app/app → app}/assets/stylesheets/application.css +0 -0
- data/demo/{demo_app/app → app}/controllers/application_controller.rb +0 -0
- data/demo/{demo_app/app → app}/helpers/application_helper.rb +0 -0
- data/demo/{demo_app/app → app}/mailers/.gitkeep +0 -0
- data/demo/{demo_app/app → app}/models/.gitkeep +0 -0
- data/demo/{demo_app/app → app}/models/celebrity.rb +0 -0
- data/demo/{demo_app/app → app}/models/comment.rb +0 -0
- data/demo/app/models/follow.rb +2 -0
- data/demo/app/models/like.rb +2 -0
- data/demo/app/models/mention.rb +2 -0
- data/demo/{demo_app/app → app}/models/movie.rb +0 -0
- data/demo/{demo_app/app → app}/models/user.rb +0 -0
- data/demo/{demo_app/app → app}/views/layouts/application.html.erb +0 -0
- data/demo/{demo_app/config.ru → config.ru} +0 -0
- data/demo/{demo_app/config → config}/application.rb +0 -0
- data/demo/{demo_app/config → config}/boot.rb +0 -0
- data/demo/{demo_app/config → config}/database.yml +0 -0
- data/demo/{demo_app/config → config}/environment.rb +0 -0
- data/demo/{demo_app/config → config}/environments/development.rb +0 -0
- data/demo/{demo_app/config → config}/environments/production.rb +0 -0
- data/demo/{demo_app/config → config}/environments/test.rb +0 -0
- data/demo/{demo_app/config → config}/initializers/backtrace_silencers.rb +0 -0
- data/demo/{demo_app/config → config}/initializers/inflections.rb +0 -0
- data/demo/{demo_app/config → config}/initializers/mime_types.rb +0 -0
- data/demo/{demo_app/config → config}/initializers/secret_token.rb +0 -0
- data/demo/{demo_app/config → config}/initializers/session_store.rb +1 -1
- data/demo/{demo_app/config → config}/initializers/wrap_parameters.rb +1 -1
- data/demo/{demo_app/config → config}/locales/en.yml +0 -0
- data/demo/{demo_app/config → config}/routes.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120115051222_create_users.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120115051234_create_movies.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120115051255_create_celebrities.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120115054646_create_follows.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120115054647_create_likes.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120221200644_create_mentions.rb +0 -0
- data/demo/{demo_app/db → db}/migrate/20120221202703_create_comments.rb +0 -0
- data/demo/{demo_app/db → db}/schema.rb +0 -1
- data/demo/{demo_app/db → db}/seeds.rb +0 -0
- data/demo/{demo_app/lib → lib}/assets/.gitkeep +0 -0
- data/demo/{demo_app/lib → lib}/tasks/.gitkeep +0 -0
- data/demo/{demo_app/public → public}/404.html +0 -0
- data/demo/{demo_app/public → public}/422.html +0 -0
- data/demo/{demo_app/public → public}/500.html +0 -0
- data/demo/{demo_app/public → public}/favicon.ico +0 -0
- data/demo/{demo_app/public → public}/index.html +0 -0
- data/demo/{demo_app/public → public}/robots.txt +0 -0
- data/demo/{demo_app/script → script}/rails +0 -0
- data/demo/{demo_app/test → test}/fixtures/.gitkeep +0 -0
- data/demo/{demo_app/test → test}/fixtures/celebrities.yml +0 -0
- data/demo/{demo_app/test → test}/fixtures/movies.yml +0 -0
- data/demo/{demo_app/test → test}/fixtures/users.yml +0 -0
- data/demo/{demo_app/test → test}/functional/.gitkeep +0 -0
- data/demo/{demo_app/test → test}/integration/.gitkeep +0 -0
- data/demo/{demo_app/test → test}/performance/browsing_test.rb +0 -0
- data/demo/{demo_app/test → test}/test_helper.rb +0 -0
- data/demo/{demo_app/test → test}/unit/.gitkeep +0 -0
- data/demo/{demo_app/test → test}/unit/celebrity_test.rb +0 -0
- data/demo/{demo_app/test → test}/unit/movie_test.rb +0 -0
- data/demo/{demo_app/test → test}/unit/user_test.rb +0 -0
- data/demo/{demo_app/vendor → vendor}/assets/javascripts/.gitkeep +0 -0
- data/demo/{demo_app/vendor → vendor}/assets/stylesheets/.gitkeep +0 -0
- data/demo/{demo_app/vendor → vendor}/plugins/.gitkeep +0 -0
- data/lib/generators/socialization/socialization_generator.rb +20 -9
- data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_follows.rb +0 -0
- data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_likes.rb +0 -0
- data/{generators/socialization/templates → lib/generators/socialization/templates/active_record}/migration_mentions.rb +0 -0
- data/lib/generators/socialization/templates/active_record/model_follow.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_like.rb +2 -0
- data/lib/generators/socialization/templates/active_record/model_mention.rb +2 -0
- data/lib/socialization.rb +3 -5
- data/lib/socialization/actors/follower.rb +74 -0
- data/lib/socialization/actors/liker.rb +74 -0
- data/lib/socialization/actors/mentioner.rb +74 -0
- data/lib/socialization/acts_as_helpers.rb +43 -0
- data/lib/socialization/config.rb +45 -0
- data/lib/socialization/helpers/string.rb +17 -0
- data/lib/socialization/stores/active_record/follow_store.rb +143 -0
- data/lib/socialization/stores/active_record/like_store.rb +143 -0
- data/lib/socialization/stores/active_record/mention_store.rb +143 -0
- data/lib/socialization/stores/redis/base.rb +8 -0
- data/lib/socialization/stores/redis/config.rb +11 -0
- data/lib/socialization/stores/redis/follow_store.rb +126 -0
- data/lib/socialization/stores/redis/like_store.rb +126 -0
- data/lib/socialization/stores/redis/mention_store.rb +126 -0
- data/lib/socialization/version.rb +1 -1
- data/lib/socialization/victims/followable.rb +38 -0
- data/lib/socialization/victims/likeable.rb +38 -0
- data/lib/socialization/victims/mentionable.rb +38 -0
- data/socialization.gemspec +3 -3
- data/test/actors/follower_test.rb +74 -0
- data/test/actors/liker_test.rb +74 -0
- data/test/actors/mentioner_test.rb +74 -0
- data/test/stores/active_record/follow_store_test.rb +121 -0
- data/test/stores/active_record/like_store_test.rb +121 -0
- data/test/stores/active_record/mention_store_test.rb +121 -0
- data/test/stores/redis/config_test.rb +30 -0
- data/test/stores/redis/follow_store_test.rb +153 -0
- data/test/stores/redis/like_store_test.rb +153 -0
- data/test/stores/redis/mention_store_test.rb +153 -0
- data/test/string_test.rb +13 -0
- data/test/test_helper.rb +70 -12
- data/test/victims/followable_test.rb +34 -0
- data/test/victims/likeable_test.rb +34 -0
- data/test/victims/mentionable_test.rb +34 -0
- data/test/world_test.rb +80 -69
- metadata +261 -176
- data/README.rdoc +0 -186
- data/demo/demo_app/app/models/follow.rb +0 -3
- data/demo/demo_app/app/models/like.rb +0 -3
- data/demo/demo_app/app/models/mention.rb +0 -3
- data/demo/demo_app/doc/README_FOR_APP +0 -2
- data/gemfiles/activerecord30.gemfile +0 -6
- data/gemfiles/activerecord30.gemfile.lock +0 -23
- data/gemfiles/activerecord31.gemfile +0 -6
- data/gemfiles/activerecord31.gemfile.lock +0 -25
- data/gemfiles/activerecord32.gemfile +0 -6
- data/gemfiles/activerecord32.gemfile.lock +0 -25
- data/generators/socialization/USAGE +0 -1
- data/generators/socialization/socialization_generator.rb +0 -15
- data/generators/socialization/templates/model_follow.rb +0 -3
- data/generators/socialization/templates/model_like.rb +0 -3
- data/generators/socialization/templates/model_mention.rb +0 -3
- data/lib/socialization/follow_store.rb +0 -14
- data/lib/socialization/followable.rb +0 -34
- data/lib/socialization/follower.rb +0 -50
- data/lib/socialization/hello.rb +0 -53
- data/lib/socialization/like_store.rb +0 -14
- data/lib/socialization/likeable.rb +0 -34
- data/lib/socialization/liker.rb +0 -54
- data/lib/socialization/mention_store.rb +0 -14
- data/lib/socialization/mentionable.rb +0 -36
- data/lib/socialization/mentioner.rb +0 -54
- data/test/follow_test.rb +0 -125
- data/test/like_test.rb +0 -125
- data/test/mention_test.rb +0 -116
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require 'rails/generators'
|
|
2
2
|
require 'rails/generators/migration'
|
|
3
3
|
|
|
4
|
+
STORES = %w(active_record redis)
|
|
5
|
+
|
|
4
6
|
class SocializationGenerator < Rails::Generators::Base
|
|
5
7
|
include Rails::Generators::Migration
|
|
6
|
-
source_root File.expand_path(File.join('
|
|
8
|
+
source_root File.expand_path(File.join('templates'), File.dirname(__FILE__))
|
|
9
|
+
class_option :store, :type => :string, :default => 'active_record', :description => "Type of datastore"
|
|
7
10
|
|
|
8
11
|
def self.next_migration_number(dirname)
|
|
9
12
|
if ActiveRecord::Base.timestamped_migrations
|
|
@@ -14,14 +17,22 @@ class SocializationGenerator < Rails::Generators::Base
|
|
|
14
17
|
end
|
|
15
18
|
|
|
16
19
|
def create_migration_file
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
options[:store].downcase!
|
|
21
|
+
unless STORES.include?(options[:store])
|
|
22
|
+
puts "Invalid store '#{options[:store]}'. The following stores are valid: #{STORES.join(', ')}."
|
|
23
|
+
exit 1
|
|
24
|
+
end
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
copy_file "#{options[:store]}/model_follow.rb", 'app/models/follow.rb'
|
|
27
|
+
copy_file "#{options[:store]}/model_like.rb", 'app/models/like.rb'
|
|
28
|
+
copy_file "#{options[:store]}/model_mention.rb", 'app/models/mention.rb'
|
|
29
|
+
|
|
30
|
+
if options[:store] == 'active_record'
|
|
31
|
+
migration_template "#{options[:store]}/migration_follows.rb", 'db/migrate/create_follows.rb'
|
|
32
|
+
sleep 1 # wait a second to have a unique migration timestamp
|
|
33
|
+
migration_template "#{options[:store]}/migration_likes.rb", 'db/migrate/create_likes.rb'
|
|
34
|
+
sleep 1 # wait a second to have a unique migration timestamp
|
|
35
|
+
migration_template "#{options[:store]}/migration_mentions.rb", 'db/migrate/create_mentions.rb'
|
|
36
|
+
end
|
|
26
37
|
end
|
|
27
38
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/lib/socialization.rb
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module ActiveRecord
|
|
2
|
+
class Base
|
|
3
|
+
def is_follower?
|
|
4
|
+
false
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Socialization
|
|
10
|
+
module Follower
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
# Specifies if self can follow {Followable} objects.
|
|
15
|
+
#
|
|
16
|
+
# @return [Boolean]
|
|
17
|
+
def is_follower?
|
|
18
|
+
true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create a new {FollowStores follow} relationship.
|
|
22
|
+
#
|
|
23
|
+
# @param [Followable] followable the object to be followed.
|
|
24
|
+
# @return [Boolean]
|
|
25
|
+
def follow!(followable)
|
|
26
|
+
raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
|
|
27
|
+
Socialization.follow_model.follow!(self, followable)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Delete a {FollowStores follow} relationship.
|
|
31
|
+
#
|
|
32
|
+
# @param [Followable] followable the object to unfollow.
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def unfollow!(followable)
|
|
35
|
+
raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
|
|
36
|
+
Socialization.follow_model.unfollow!(self, followable)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Toggles a {FollowStores follow} relationship.
|
|
40
|
+
#
|
|
41
|
+
# @param [Followable] followable the object to follow/unfollow.
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def toggle_follow!(followable)
|
|
44
|
+
raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
|
|
45
|
+
if follows?(followable)
|
|
46
|
+
unfollow!(followable)
|
|
47
|
+
false
|
|
48
|
+
else
|
|
49
|
+
follow!(followable)
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Specifies if self follows a {Followable} object.
|
|
55
|
+
#
|
|
56
|
+
# @param [Followable] followable the {Followable} object to test against.
|
|
57
|
+
# @return [Boolean]
|
|
58
|
+
def follows?(followable)
|
|
59
|
+
raise ArgumentError, "#{followable} is not followable!" unless followable.respond_to?(:is_followable?) && followable.is_followable?
|
|
60
|
+
Socialization.follow_model.follows?(self, followable)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns all the followables of a certain type that are followed by self
|
|
64
|
+
#
|
|
65
|
+
# @params [Followable] klass the type of {Followable} you want
|
|
66
|
+
# @params [Hash] opts a hash of options
|
|
67
|
+
# @return [Array<Followable, Numeric>] An array of Followable objects or IDs
|
|
68
|
+
def followables(klass, opts = {})
|
|
69
|
+
Socialization.follow_model.followables(self, klass, opts)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module ActiveRecord
|
|
2
|
+
class Base
|
|
3
|
+
def is_liker?
|
|
4
|
+
false
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Socialization
|
|
10
|
+
module Liker
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
# Specifies if self can like {Likeable} objects.
|
|
15
|
+
#
|
|
16
|
+
# @return [Boolean]
|
|
17
|
+
def is_liker?
|
|
18
|
+
true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create a new {LikeStores like} relationship.
|
|
22
|
+
#
|
|
23
|
+
# @param [Likeable] likeable the object to be liked.
|
|
24
|
+
# @return [Boolean]
|
|
25
|
+
def like!(likeable)
|
|
26
|
+
raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
|
|
27
|
+
Socialization.like_model.like!(self, likeable)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Delete a {LikeStores like} relationship.
|
|
31
|
+
#
|
|
32
|
+
# @param [Likeable] likeable the object to unlike.
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def unlike!(likeable)
|
|
35
|
+
raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
|
|
36
|
+
Socialization.like_model.unlike!(self, likeable)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Toggles a {LikeStores like} relationship.
|
|
40
|
+
#
|
|
41
|
+
# @param [Likeable] likeable the object to like/unlike.
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def toggle_like!(likeable)
|
|
44
|
+
raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
|
|
45
|
+
if likes?(likeable)
|
|
46
|
+
unlike!(likeable)
|
|
47
|
+
false
|
|
48
|
+
else
|
|
49
|
+
like!(likeable)
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Specifies if self likes a {Likeable} object.
|
|
55
|
+
#
|
|
56
|
+
# @param [Likeable] likeable the {Likeable} object to test against.
|
|
57
|
+
# @return [Boolean]
|
|
58
|
+
def likes?(likeable)
|
|
59
|
+
raise ArgumentError, "#{likeable} is not likeable!" unless likeable.respond_to?(:is_likeable?) && likeable.is_likeable?
|
|
60
|
+
Socialization.like_model.likes?(self, likeable)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns all the likeables of a certain type that are liked by self
|
|
64
|
+
#
|
|
65
|
+
# @params [Likeable] klass the type of {Likeable} you want
|
|
66
|
+
# @params [Hash] opts a hash of options
|
|
67
|
+
# @return [Array<Likeable, Numeric>] An array of Likeable objects or IDs
|
|
68
|
+
def likeables(klass, opts = {})
|
|
69
|
+
Socialization.like_model.likeables(self, klass, opts)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module ActiveRecord
|
|
2
|
+
class Base
|
|
3
|
+
def is_mentioner?
|
|
4
|
+
false
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Socialization
|
|
10
|
+
module Mentioner
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
# Specifies if self can mention {Mentionable} objects.
|
|
15
|
+
#
|
|
16
|
+
# @return [Boolean]
|
|
17
|
+
def is_mentioner?
|
|
18
|
+
true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Create a new {MentionStores mention} relationship.
|
|
22
|
+
#
|
|
23
|
+
# @param [Mentionable] mentionable the object to be mentioned.
|
|
24
|
+
# @return [Boolean]
|
|
25
|
+
def mention!(mentionable)
|
|
26
|
+
raise ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable?
|
|
27
|
+
Socialization.mention_model.mention!(self, mentionable)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Delete a {MentionStores mention} relationship.
|
|
31
|
+
#
|
|
32
|
+
# @param [Mentionable] mentionable the object to unmention.
|
|
33
|
+
# @return [Boolean]
|
|
34
|
+
def unmention!(mentionable)
|
|
35
|
+
raise ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable?
|
|
36
|
+
Socialization.mention_model.unmention!(self, mentionable)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Toggles a {MentionStores mention} relationship.
|
|
40
|
+
#
|
|
41
|
+
# @param [Mentionable] mentionable the object to mention/unmention.
|
|
42
|
+
# @return [Boolean]
|
|
43
|
+
def toggle_mention!(mentionable)
|
|
44
|
+
raise ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable?
|
|
45
|
+
if mentions?(mentionable)
|
|
46
|
+
unmention!(mentionable)
|
|
47
|
+
false
|
|
48
|
+
else
|
|
49
|
+
mention!(mentionable)
|
|
50
|
+
true
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Specifies if self mentions a {Mentionable} object.
|
|
55
|
+
#
|
|
56
|
+
# @param [Mentionable] mentionable the {Mentionable} object to test against.
|
|
57
|
+
# @return [Boolean]
|
|
58
|
+
def mentions?(mentionable)
|
|
59
|
+
raise ArgumentError, "#{mentionable} is not mentionable!" unless mentionable.respond_to?(:is_mentionable?) && mentionable.is_mentionable?
|
|
60
|
+
Socialization.mention_model.mentions?(self, mentionable)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns all the mentionables of a certain type that are mentioned by self
|
|
64
|
+
#
|
|
65
|
+
# @params [Mentionable] klass the type of {Mentionable} you want
|
|
66
|
+
# @params [Hash] opts a hash of options
|
|
67
|
+
# @return [Array<Mentionable, Numeric>] An array of Mentionable objects or IDs
|
|
68
|
+
def mentionables(klass, opts = {})
|
|
69
|
+
Socialization.mention_model.mentionables(self, klass, opts)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
%w(helpers stores actors victims).each do |path|
|
|
4
|
+
Dir["#{File.dirname(__FILE__)}/#{path}/**/*.rb"].each { |f| require(f) }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
module Socialization
|
|
8
|
+
module ActsAsHelpers
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
module ClassMethods
|
|
12
|
+
# Make the current class a {Socialization::Follower}
|
|
13
|
+
def acts_as_follower(opts = {})
|
|
14
|
+
include Socialization::Follower
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Make the current class a {Socialization::Followable}
|
|
18
|
+
def acts_as_followable(opts = {})
|
|
19
|
+
include Socialization::Followable
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Make the current class a {Socialization::Liker}
|
|
23
|
+
def acts_as_liker(opts = {})
|
|
24
|
+
include Socialization::Liker
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Make the current class a {Socialization::Likeable}
|
|
28
|
+
def acts_as_likeable(opts = {})
|
|
29
|
+
include Socialization::Likeable
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Make the current class a {Socialization::Mentioner}
|
|
33
|
+
def acts_as_mentioner(opts = {})
|
|
34
|
+
include Socialization::Mentioner
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Make the current class a {Socialization::Mentionable}
|
|
38
|
+
def acts_as_mentionable(opts = {})
|
|
39
|
+
include Socialization::Mentionable
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Socialization
|
|
2
|
+
class << self
|
|
3
|
+
def follow_model
|
|
4
|
+
if @follow_model
|
|
5
|
+
@follow_model
|
|
6
|
+
elsif defined?(::Follow)
|
|
7
|
+
::Follow
|
|
8
|
+
else
|
|
9
|
+
raise RuntimeError.new("No Follow model has been defined.")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def follow_model=(klass)
|
|
14
|
+
@follow_model = klass
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def like_model
|
|
18
|
+
if @like_model
|
|
19
|
+
@like_model
|
|
20
|
+
elsif defined?(::Like)
|
|
21
|
+
::Like
|
|
22
|
+
else
|
|
23
|
+
raise RuntimeError.new("No Like model has been defined.")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def like_model=(klass)
|
|
28
|
+
@like_model = klass
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def mention_model
|
|
32
|
+
if @mention_model
|
|
33
|
+
@mention_model
|
|
34
|
+
elsif defined?(::Mention)
|
|
35
|
+
::Mention
|
|
36
|
+
else
|
|
37
|
+
raise RuntimeError.new("No Mention model has been defined.")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def mention_model=(klass)
|
|
42
|
+
@mention_model = klass
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|