acts_as_followable 0.1.8 → 0.1.9
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/README.rdoc +1 -1
- data/app/models/follow.rb +2 -2
- data/lib/acts_as_followable.rb +1 -0
- data/lib/acts_as_followable/followable.rb +9 -8
- data/lib/acts_as_followable/lib.rb +16 -0
- data/lib/acts_as_followable/version.rb +1 -1
- metadata +4 -3
data/README.rdoc
CHANGED
data/app/models/follow.rb
CHANGED
@@ -4,6 +4,6 @@ class Follow < ActiveRecord::Base
|
|
4
4
|
|
5
5
|
scope :for_follower_type, lambda { |follower_type| where("follower_type = ?", follower_type) }
|
6
6
|
scope :for_followable_type, lambda { |followable_type| where("followable_type = ?", followable_type) }
|
7
|
-
scope :for_follower, lambda { |follower| where(["follower_id = ?", follower.id]).for_follower_type(follower
|
8
|
-
scope :for_followable, lambda { |followable| where(["followable_id = ?", followable.id]).for_followable_type(followable
|
7
|
+
scope :for_follower, lambda { |follower| where(["follower_id = ?", follower.id]).for_follower_type(ActsAsFollowable::Lib.class_name(follower)) }
|
8
|
+
scope :for_followable, lambda { |followable| where(["followable_id = ?", followable.id]).for_followable_type(ActsAsFollowable::Lib.class_name(followable)) }
|
9
9
|
end
|
data/lib/acts_as_followable.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
module ActsAsFollowable
|
2
2
|
module Followable
|
3
|
-
|
3
|
+
|
4
4
|
def self.included(base)
|
5
5
|
base.extend ClassMethods
|
6
6
|
end
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def acts_as_followable
|
10
|
+
include ActsAsFollowable::Lib::InstanceMethods
|
10
11
|
include ActsAsFollowable::Followable::InstanceMethods
|
11
12
|
|
12
|
-
scope :following, lambda{|followable| includes(:follows).where(['follows.followable_id=? AND follows.followable_type=?', followable.id, followable
|
13
|
-
scope :followed_by, lambda{|follower| includes(:followings).where(['follows.follower_id=? AND follows.follower_type=?', follower.id, follower
|
13
|
+
scope :following, lambda{|followable| includes(:follows).where(['follows.followable_id=? AND follows.followable_type=?', followable.id, ActsAsFollowable::Lib.class_name(followable)]) }
|
14
|
+
scope :followed_by, lambda{|follower| includes(:followings).where(['follows.follower_id=? AND follows.follower_type=?', follower.id, ActsAsFollowable::Lib.class_name(follower)]) }
|
14
15
|
|
15
16
|
has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'
|
16
17
|
has_many :follows, :as => :follower, :dependent => :destroy
|
@@ -47,7 +48,7 @@ module ActsAsFollowable
|
|
47
48
|
def follow(followable)
|
48
49
|
follow = follow_for_follawable(followable).first
|
49
50
|
if follow.blank?
|
50
|
-
Follow.create(:followable => followable, :
|
51
|
+
Follow.create(:followable_id => followable.id, :followable_type => class_name(followable), :follower_id => self.id, :follower_type => class_name(self))
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -65,12 +66,12 @@ module ActsAsFollowable
|
|
65
66
|
|
66
67
|
# Destroys all followers of a given type
|
67
68
|
def destroy_followers_by_type(type)
|
68
|
-
Follow.where(['follows.followable_id=? AND follows.followable_type=? AND follows.follower_type=?', self.id, self
|
69
|
+
Follow.where(['follows.followable_id=? AND follows.followable_type=? AND follows.follower_type=?', self.id, class_name(self), type]).destroy_all
|
69
70
|
end
|
70
71
|
|
71
72
|
# Destroys all followings of a given type
|
72
73
|
def destroy_followings_by_type(type)
|
73
|
-
Follow.where(['follows.follower_id=? AND follows.follower_type=? AND follows.followable_type=?', self.id, self
|
74
|
+
Follow.where(['follows.follower_id=? AND follows.follower_type=? AND follows.followable_type=?', self.id, class_name(self), type]).destroy_all
|
74
75
|
end
|
75
76
|
|
76
77
|
# Returns true if the current instance is followed by the passed record
|
@@ -81,11 +82,11 @@ module ActsAsFollowable
|
|
81
82
|
private
|
82
83
|
|
83
84
|
def follow_for_follawable(followable)
|
84
|
-
Follow.where(["follower_id = ? AND follower_type = ? AND followable_id = ? AND followable_type = ?", self.id, self
|
85
|
+
Follow.where(["follower_id = ? AND follower_type = ? AND followable_id = ? AND followable_type = ?", self.id, class_name(self), followable.id, class_name(followable)])
|
85
86
|
end
|
86
87
|
|
87
88
|
def follow_for_follower(follower)
|
88
|
-
Follow.where(["follower_id = ? AND follower_type = ? AND followable_id = ? AND followable_type = ?", follower.id, follower
|
89
|
+
Follow.where(["follower_id = ? AND follower_type = ? AND followable_id = ? AND followable_type = ?", follower.id, class_name(follower), self.id, class_name(self)])
|
89
90
|
end
|
90
91
|
|
91
92
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_followable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kristijan Sedlak
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- Rakefile
|
32
32
|
- app/models/follow.rb
|
33
33
|
- lib/acts_as_followable/followable.rb
|
34
|
+
- lib/acts_as_followable/lib.rb
|
34
35
|
- lib/acts_as_followable/railtie.rb
|
35
36
|
- lib/acts_as_followable/version.rb
|
36
37
|
- lib/acts_as_followable.rb
|