Module: EffectivePollsUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_polls_user.rb
Overview
EffectivePollsUser
Mark your user model with effective_polls_user to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #available_polls ⇒ Object
- #default_poll_audience_scopes ⇒ Object
-
#poll_audience_scope(value) ⇒ Object
Turns the given audience_scope value into the actual ActiveRecord::Relation scope.
-
#poll_audience_scopes ⇒ Object
The list of all available audience scopes for the Poll Selected Users.
Instance Method Details
#available_polls ⇒ Object
100 101 102 |
# File 'app/models/concerns/effective_polls_user.rb', line 100 def available_polls Effective::Poll.available.select { |poll| poll.available_for?(self) } end |
#default_poll_audience_scopes ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/models/concerns/effective_polls_user.rb', line 27 def default_poll_audience_scopes scopes = [ ['All Users', :all] ] if self.class.try(:effective_memberships_user?) scopes += [ ['All members', :members], ['All removed members', :membership_removed], ['All members in good standing', :membership_in_good_standing], ['All members not in good standing', :membership_not_in_good_standing], ['All members renewed this period', :membership_renewed_this_period], ] scopes += EffectiveMemberships.Category.sorted.map do |category| ["All #{category} members", "members_with_category_id_#{category.id}"] end end if self.class.try(:effective_committees_user?) scopes += Effective::Committee.sorted.map do |committee| ["All #{committee} committee members", "with_committee_id_#{committee.id}"] end end if self.class.try(:acts_as_role_restricted?) scopes += EffectiveRoles.roles.map do |role| ["All #{role} role users", "with_role_id_#{role}"] end end if self.class.try(:effective_mentorships_user?) Effective::MentorshipCycle.sorted.each do |cycle| scopes += [ ["All grouped participants in #{cycle}", "mentorships_with_groups_id_#{cycle.id}"], ["All grouped mentors in #{cycle}", "mentorships_mentors_with_groups_id_#{cycle.id}"], ["All grouped mentees in #{cycle}", "mentorships_mentees_with_groups_id_#{cycle.id}"], ] end end scopes end |
#poll_audience_scope(value) ⇒ Object
Turns the given audience_scope value into the actual ActiveRecord::Relation scope
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/concerns/effective_polls_user.rb', line 72 def poll_audience_scope(value) collection = self.class.respond_to?(:unarchived) ? self.class.unarchived : self.class # Parse the value name, id = value.to_s.split('_id_') case name.try(:to_sym) when :members_with_category return collection.members_with_category(EffectiveMemberships.Category.find_by_id(id)) when :with_committee return collection.with_committee(Effective::Committee.find_by_id(id)) when :with_role return collection.with_role(id) when :mentorships_with_groups return collection.mentorships_with_groups(Effective::MentorshipCycle.find_by_id(id)) when :mentorships_mentors_with_groups return collection.mentorships_mentors_with_groups(Effective::MentorshipCycle.find_by_id(id)) when :mentorships_mentees_with_groups return collection.mentorships_mentees_with_groups(Effective::MentorshipCycle.find_by_id(id)) end # Otherwise we don't know what this scope is raise("unknown poll_audience_scope for #{value}. Expected #{self.class.name} to have a scope named #{value}") unless collection.respond_to?(value) # If we respond to the fill value, call it collection.send(value) end |
#poll_audience_scopes ⇒ Object
The list of all available audience scopes for the Poll Selected Users
23 24 25 |
# File 'app/models/concerns/effective_polls_user.rb', line 23 def poll_audience_scopes default_poll_audience_scopes() end |