Module: Webring::Navigation
- Included in:
- Member
- Defined in:
- app/models/concerns/webring/navigation.rb
Overview
Requires model to have ‘uid` and `created_at` columns
Instance Method Summary collapse
-
#find_next(source_member_uid) ⇒ Object
Find the next member in the webring after the current one If current member is the last, return the first member (ring concept).
-
#find_previous(source_member_uid) ⇒ Object
Find the previous member in the webring before the current one If current member is the first, return the last member (ring concept).
-
#find_random(source_member_uid: nil) ⇒ Object
Find a random member, excluding the current one if provided If current member is the only one, return it.
Instance Method Details
#find_next(source_member_uid) ⇒ Object
Find the next member in the webring after the current one If current member is the last, return the first member (ring concept)
6 7 8 9 10 11 |
# File 'app/models/concerns/webring/navigation.rb', line 6 def find_next(source_member_uid) source_member = active.find_by(uid: source_member_uid) return first_active_member unless source_member find_next_active_member(source_member) || first_active_member end |
#find_previous(source_member_uid) ⇒ Object
Find the previous member in the webring before the current one If current member is the first, return the last member (ring concept)
15 16 17 18 19 20 |
# File 'app/models/concerns/webring/navigation.rb', line 15 def find_previous(source_member_uid) source_member = active.find_by(uid: source_member_uid) return last_active_member unless source_member find_previous_active_member(source_member) || last_active_member end |
#find_random(source_member_uid: nil) ⇒ Object
Find a random member, excluding the current one if provided If current member is the only one, return it
24 25 26 27 28 29 30 31 32 |
# File 'app/models/concerns/webring/navigation.rb', line 24 def find_random(source_member_uid: nil) scope = active scope = scope.where.not(uid: source_member_uid) if source_member_uid.present? return scope.order('RANDOM()').first if scope.exists? return active.find_by(uid: source_member_uid) if source_member_uid.present? nil end |