Skip to content

Commit

Permalink
Remove apply_finder_method (It's going to be deprecated in Rails 4).
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael committed Sep 4, 2013
1 parent 6d22a0a commit 4f9c4cc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
18 changes: 11 additions & 7 deletions lib/acts_as_follower/followable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ def blocked_followers_count
self.followings.blocked.count
end

# Returns the following records.
# Returns the followings records scoped
def followers_scoped
self.followings.includes(:follower)
end

def followers(options={})
self.followings.unblocked.includes(:follower).
apply_finder_options(options,true).
to_a.collect{|f| f.follower}
followers_scope = followers_scoped.unblocked
followers_scope = apply_options_to_scope(followers_scope, options)
followers_scope.to_a.collect{|f| f.follower}
end

def blocks(options={})
self.followings.blocked.includes(:follower).
apply_finder_options(options, true).
to_a.collect{|f| f.follower}
blocked_followers_scope = followers_scoped.blocked
blocked_followers_scope = apply_options_to_scope(blocked_followers_scope, options)
blocked_followers_scope.to_a.collect{|f| f.follower}
end

# Returns true if the current instance is followed by the passed record
Expand Down
11 changes: 9 additions & 2 deletions lib/acts_as_follower/follower.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ def stop_following(followable)
end
end

# returns the follows records to the current instance
def follows_scoped
self.follows.unblocked.includes(:followable)
end

# Returns the follow records related to this instance by type.
def follows_by_type(followable_type, options={})
self.follows.unblocked.includes(:followable).for_followable_type(followable_type).apply_finder_options(options, true)
follows_scope = follows_scoped.for_followable_type(followable_type)
follows_scope = apply_options_to_scope(follows_scope, options)
end

# Returns the follow records related to this instance with the followable included.
def all_follows(options={})
self.follows.unblocked.includes(:followable).apply_finder_options(options, true)
follows_scope = follows_scoped
follows_scope = apply_options_to_scope(follows_scope, options)
end

# Returns the actual records which this instance is following.
Expand Down
18 changes: 18 additions & 0 deletions lib/acts_as_follower/follower_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,23 @@ def parent_class_name(obj)
return obj.class.name
end

def apply_options_to_scope(scope, options = {})
if options.has_key?(:limit)
scope = scope.limit(options[:limit])
end
if options.has_key?(:includes)
scope = scope.includes(options[:includes])
end
if options.has_key?(:joins)
scope = scope.joins(options[:joins])
end
if options.has_key?(:where)
scope = scope.order(options[:where])
end
if options.has_key?(:order)
scope = scope.order(options[:order])
end
scope
end
end
end

0 comments on commit 4f9c4cc

Please sign in to comment.