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
83 84 85 |
# File 'app/models/concerns/effective_polls_user.rb', line 83 def available_polls Effective::Poll.available.select { |poll| poll.available_for?(self) } end |
#default_poll_audience_scopes ⇒ Object
26 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 |
# File 'app/models/concerns/effective_polls_user.rb', line 26 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 scopes end |
#poll_audience_scope(value) ⇒ Object
Turns the given audience_scope value into the actual ActiveRecord::Relation scope
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/concerns/effective_polls_user.rb', line 61 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) 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 |
# File 'app/models/concerns/effective_polls_user.rb', line 23 def poll_audience_scopes end |