Module: Interest::FollowRequestable::FollowRequester

Extended by:
ActiveSupport::Concern
Defined in:
lib/interest/follow_requestable/follow_requester.rb

Defined Under Namespace

Modules: ClassMethods Classes: FollowOrRequestToFollow

Instance Method Summary collapse

Instance Method Details

#cancel_request_to_follow(requestee) ⇒ Object



33
34
35
# File 'lib/interest/follow_requestable/follow_requester.rb', line 33

def cancel_request_to_follow(requestee)
  follow_requester_collection_for(requestee).delete requestee
end

#follow_or_request_to_follow!(other) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/interest/follow_requestable/follow_requester.rb', line 45

def follow_or_request_to_follow!(other)
  if required_request_to_follow? other
    returned = request_to_follow! other
    which    = :request_to_follow
  else
    returned = follow! other
    which    = :follow
  end

  FollowOrRequestToFollow.new which, returned, other
end

#has_requested_to_follow?(requestee) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/interest/follow_requestable/follow_requester.rb', line 37

def has_requested_to_follow?(requestee)
  follow_requester_collection_for(requestee).include? requestee
end

#request_to_follow(requestee, raise_record_invalid = false) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/interest/follow_requestable/follow_requester.rb', line 19

def request_to_follow(requestee, raise_record_invalid = false)
  outgoing_follow_requests.create!(followee: requestee)
rescue ActiveRecord::RecordInvalid => exception
  raise_record_invalid ? (raise exception) : nil
rescue ActiveRecord::RecordNotUnique
  outgoing_follow_requests.find_by(followee: requestee)
end

#request_to_follow!(requestee) ⇒ Object



27
28
29
30
31
# File 'lib/interest/follow_requestable/follow_requester.rb', line 27

def request_to_follow!(requestee)
  request_to_follow(requestee, true)
rescue ActiveRecord::RecordInvalid => exception
  raise Interest::FollowRequestable::Rejected.new(exception)
end

#required_request_to_follow?(requestee) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/interest/follow_requestable/follow_requester.rb', line 15

def required_request_to_follow?(requestee)
  requestee.follow_requestee? and requestee.requires_request_to_follow?(self)
end

#valid_follow_request_for?(requestee) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/interest/follow_requestable/follow_requester.rb', line 41

def valid_follow_request_for?(requestee)
  not (self == requestee or not follow_requestable?(requestee) or (follower? and following? requestee))
end