Module: Interest::Followable::Follower

Extended by:
ActiveSupport::Concern
Defined in:
lib/interest/followable/follower.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#follow(followee, raise_record_invalid = false) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/interest/followable/follower.rb', line 19

def follow(followee, raise_record_invalid = false)
  following_relationships.create!(followee: followee)
rescue ActiveRecord::RecordInvalid => exception
  raise_record_invalid ? (raise exception) : nil
rescue ActiveRecord::RecordNotUnique
  if follow_requester? and followee.follow_requestee?
    outgoing_follow_requests.find_by(followee: followee).try(:accept!)
  end or following_relationships.find_by(followee: followee)
end

#follow!(followee) ⇒ Object



29
30
31
32
33
# File 'lib/interest/followable/follower.rb', line 29

def follow!(followee)
  follow(followee, true)
rescue ActiveRecord::RecordInvalid => exception
  raise Interest::Followable::Rejected.new(exception)
end

#following?(followee) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/interest/followable/follower.rb', line 15

def following?(followee)
  follower_collection_for(followee).include? followee
end

#unfollow(followee) ⇒ Object



35
36
37
# File 'lib/interest/followable/follower.rb', line 35

def unfollow(followee)
  follower_collection_for(followee).delete followee
end

#valid_following_for?(followee) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/interest/followable/follower.rb', line 39

def valid_following_for?(followee)
  not (followee == self or not followable?(followee))
end