Skip to content

Commit

Permalink
default is to use joins for the followers/following by_type methods, …
Browse files Browse the repository at this point in the history
…optionally have includes, attribution in the readme
  • Loading branch information
tcocca committed Oct 16, 2011
1 parent 7ba0a8d commit 9401afd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
18 changes: 10 additions & 8 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ If you have updates or patches or want to contribute I would love to see what yo

Thanks to everyone for their interest and time in committing to making this plugin better.

* dougal (Douglas F Shearer) - http://github.com/dougal
* jdg (Jonathan George) - http://github.com/jdg
* m3talsmith (Michael Christenson II) - http://github.com/m3talsmith
* joergbattermann (Jörg Battermann) - http://github.com/joergbattermann
* TomK32 (Thomas R. Koll) - http://github.com/TomK32
* drcapulet (Alex Coomans) - http://github.com/drcapulet
* jhchabran (Jean Hadrien Chabran) - http://github.com/jhchabran
* arthurgeek (Arthur Zapparoli) - http://github.com/arthurgeek
* dougal (Douglas F Shearer) - https://github.com/dougal
* jdg (Jonathan George) - https://github.com/jdg
* m3talsmith (Michael Christenson II) - https://github.com/m3talsmith
* joergbattermann (Jörg Battermann) - https://github.com/joergbattermann
* TomK32 (Thomas R. Koll) - https://github.com/TomK32
* drcapulet (Alex Coomans) - https://github.com/drcapulet
* jhchabran (Jean Hadrien Chabran) - https://github.com/jhchabran
* arthurgeek (Arthur Zapparoli) - https://github.com/arthurgeek
* james2m (James McCarthy) - https://github.com/james2m
* peterjm (Peter McCracken) - https://github.com/peterjm

Please let me know if I missed you.

Expand Down
5 changes: 4 additions & 1 deletion lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ def followers_count
# Returns the followers by a given type
def followers_by_type(follower_type, options={})
follows = follower_type.constantize.
includes(:follows).
joins(:follows).
where('follows.blocked' => false,
'follows.followable_id' => self.id,
'follows.followable_type' => parent_class_name(self),
'follows.follower_type' => follower_type)
if options.has_key?(:limit)
follows = follows.limit(options[:limit])
end
if options.has_key?(:includes)
follows = follows.includes(options[:includes])
end
follows
end

Expand Down
5 changes: 4 additions & 1 deletion lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ def all_following(options={})
# Returns the actual records of a particular type which this record is following.
def following_by_type(followable_type, options={})
followables = followable_type.constantize.
includes(:followings).
joins(:followings).
where('follows.blocked' => false,
'follows.follower_id' => self.id,
'follows.follower_type' => parent_class_name(self),
'follows.followable_type' => followable_type)
if options.has_key?(:limit)
followables = followables.limit(options[:limit])
end
if options.has_key?(:includes)
followables = followables.includes(options[:includes])
end
followables
end

Expand Down
2 changes: 1 addition & 1 deletion test/acts_as_follower_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ActsAsFollowerTest < ActiveSupport::TestCase
should "accept AR options" do
@metallica = Factory(:metallica)
@sam.follow(@metallica)
assert_equal 1, @sam.following_by_type('Band', :limit => 1).count
assert_equal 1, @sam.following_by_type('Band', :limit => 1).to_a.size
end
end

Expand Down

0 comments on commit 9401afd

Please sign in to comment.