lib/popular/popular.rb in popular-0.5.1 vs lib/popular/popular.rb in popular-0.6.0

- old
+ new

@@ -3,19 +3,36 @@ module Popular extend ActiveSupport::Concern included do |base| + has_many :followings, class_name: 'Popular::Friendship', as: :popular_model, dependent: :destroy + has_many :followeds, through: :followings, source: :friend, source_type: base + has_many :inverse_followings, class_name: 'Popular::Friendship', as: :friend, foreign_key: :friend_id + has_many :followers, through: :inverse_followings, source: :popular_model, source_type: base + has_many :friendships, class_name: 'Popular::Friendship', as: :popular_model, dependent: :destroy has_many :friends, through: :friendships, source_type: base has_many :inverse_friendships, class_name: 'Popular::Friendship', as: :friend, foreign_key: :friend_id has_many :inverse_friends, through: :inverse_friendships, source: :popular_model, source_type: base include ActiveSupport::Callbacks define_callbacks :befriend, :unfriend [:before_unfriend, :after_unfriend, :before_befriend, :after_befriend].each do |callback| send callback + end + + aliases = { + befriend: [:follow], + befriend!: [:follow!], + unfriend: [:unfollow], + friends_with?: [:following?], + friended_by?: [:followed_by?] + } + + aliases.each do |method, links| + links.each { |linked_method| alias_method( linked_method, method ) } end end # Adds a friend to an instance's friend's list #