acts_as_followable 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -120,4 +120,4 @@ You can also query Follow model records like this:
120
120
 
121
121
  * {xpepermint}[http://github.com/xpepermint] (Author)
122
122
  * {afhammad}[http://github.com/afhammad]
123
- * (jeanmartin)[http://github.com/jeanmartin]
123
+ * {jeanmartin}[http://github.com/jeanmartin]
@@ -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.class.name) }
8
- scope :for_followable, lambda { |followable| where(["followable_id = ?", followable.id]).for_followable_type(followable.class.name) }
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
@@ -1,4 +1,5 @@
1
1
  %w( acts_as_followable/version
2
+ acts_as_followable/lib
2
3
  acts_as_followable/followable
3
4
  acts_as_followable/railtie
4
5
  ).each do |lib|
@@ -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.class.name]) }
13
- scope :followed_by, lambda{|follower| includes(:followings).where(['follows.follower_id=? AND follows.follower_type=?', follower.id, follower.class.name]) }
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, :follower => self)
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.class.name, type]).destroy_all
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.class.name, type]).destroy_all
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.class.name, followable.id, followable.class.name])
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.class.name, self.id, self.class.name])
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
@@ -0,0 +1,16 @@
1
+ module ActsAsFollowable
2
+ module Lib
3
+
4
+ def self.class_name(obj)
5
+ return obj.class.name
6
+ end
7
+
8
+ module InstanceMethods
9
+ def class_name(obj)
10
+ return obj.class.name
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+
@@ -2,7 +2,7 @@ module ActsAsFollowable
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 8
5
+ TINY = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 8
10
- version: 0.1.8
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