Class: Effective::Committee
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Committee
- Defined in:
- app/models/effective/committee.rb
Instance Method Summary collapse
-
#build_committee_member(user:) ⇒ Object
Find-active-or-build-new.
- #children ⇒ Object
-
#committee_member(user:) ⇒ Object
Returns the user’s currently-active term on this committee, or nil.
-
#committee_members_for(user:) ⇒ Object
All terms (active and expired) a user has served on this committee.
- #emails ⇒ Object
- #to_s ⇒ Object
- #users ⇒ Object
Instance Method Details
#build_committee_member(user:) ⇒ Object
Find-active-or-build-new. If the user has no active term, build a fresh row (expired terms are history and are not edited in place through this helper).
68 69 70 |
# File 'app/models/effective/committee.rb', line 68 def build_committee_member(user:) committee_member(user: user) || committee_members.build(user: user) end |
#children ⇒ Object
80 81 82 83 84 |
# File 'app/models/effective/committee.rb', line 80 def children committee_folders .select { |folder| folder.committee_folder_id.blank? } .flat_map { |folder| [folder] + folder.children } end |
#committee_member(user:) ⇒ Object
Returns the user’s currently-active term on this committee, or nil. For the full history including expired terms, use committee_members_for(user:).
57 58 59 |
# File 'app/models/effective/committee.rb', line 57 def committee_member(user:) committee_members.find { |member| member.user_id == user.id && member.active? } end |
#committee_members_for(user:) ⇒ Object
All terms (active and expired) a user has served on this committee.
62 63 64 |
# File 'app/models/effective/committee.rb', line 62 def committee_members_for(user:) committee_members.select { |member| member.user_id == user.id } end |
#emails ⇒ Object
76 77 78 |
# File 'app/models/effective/committee.rb', line 76 def emails committee_members.reject(&:marked_for_destruction?).select(&:active?).map(&:email).compact.join(', ') end |
#to_s ⇒ Object
51 52 53 |
# File 'app/models/effective/committee.rb', line 51 def to_s title.presence || 'New Committee' end |
#users ⇒ Object
72 73 74 |
# File 'app/models/effective/committee.rb', line 72 def users committee_members.reject(&:marked_for_destruction?).map(&:user) end |