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
-
#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
63 64 65 |
# File 'app/models/concerns/effective_polls_user.rb', line 63 def available_polls Effective::Poll.available.select { |poll| poll.available_for?(self) } end |
#poll_audience_scope(value) ⇒ Object
Turns the given audience_scope value into the actual ActiveRecord::Relation scope
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/effective_polls_user.rb', line 46 def poll_audience_scope(value) collection = self.class.respond_to?(:unarchived) ? self.class.unarchived : self.class # If we respond to the fill value, call it return collection.send(value) if collection.respond_to?(value) # Parse the value name, id = value.to_s.split('_id_') case name.try(:to_sym) when :members_with_category collection.members_with_category(EffectiveMemberships.Category.find(id)) else raise("unknown poll_audience_scope for #{value}") end end |
#poll_audience_scopes ⇒ Object
The list of all available audience scopes for the Poll Selected Users
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/concerns/effective_polls_user.rb', line 23 def 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 scopes end |