module HasFriendship::Friendable

Public Class Methods

friendable?() click to toggle source
# File lib/has_friendship/friendable.rb, line 31
def self.friendable?
  true
end

Public Instance Methods

friendable?() click to toggle source
# File lib/has_friendship/friendable.rb, line 3
def friendable?
  false
end
has_friendship() click to toggle source
# File lib/has_friendship/friendable.rb, line 7
def has_friendship
  class_eval do
    has_many :friendships, as: :friendable,
             class_name: "HasFriendship::Friendship", dependent: :destroy

    has_many :blocked_friends,
              -> { where friendships: { status: 3 } },
              through: :friendships,
              source: :friend

    has_many :friends,
              -> { where friendships: { status: 2 } },
              through: :friendships

    has_many :requested_friends,
              -> { where friendships: { status: 1 } },
              through: :friendships,
              source: :friend

    has_many :pending_friends,
              -> { where friendships: { status: 0 } },
              through: :friendships,
              source: :friend

    def self.friendable?
      true
    end
  end

  include HasFriendship::Friendable::InstanceMethods
  include HasFriendship::Extender
end