Class: Effective::Committee

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/committee.rb

Instance Method Summary collapse

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).



69
70
71
# File 'app/models/effective/committee.rb', line 69

def build_committee_member(user:)
  committee_member(user: user) || committee_members.build(user: user)
end

#childrenObject



81
82
83
84
85
# File 'app/models/effective/committee.rb', line 81

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 { |cm| cm.user_id == user.id && cm.active? }
end

#committee_members_for(user:) ⇒ Object

All terms (active and expired) a user has served on this committee. Do not add uniq here



63
64
65
# File 'app/models/effective/committee.rb', line 63

def committee_members_for(user:)
  committee_members.select { |cm| cm.user_id == user.id }
end

#emailsObject



77
78
79
# File 'app/models/effective/committee.rb', line 77

def emails
  committee_members.select(&:active?).map(&:email).compact.uniq.join(', ')
end

#to_sObject



51
52
53
# File 'app/models/effective/committee.rb', line 51

def to_s
  title.presence || 'New Committee'
end

#usersObject



73
74
75
# File 'app/models/effective/committee.rb', line 73

def users
  committee_members.map(&:user).uniq
end