Module: HasFriendship::Friendable

Defined in:
lib/has_friendship/friendable.rb

Defined Under Namespace

Modules: InstanceMethods

Instance Method Summary collapse

Instance Method Details

#friendable?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/has_friendship/friendable.rb', line 3

def friendable?
  false
end

#has_friendshipObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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