Sha256: 3f0c54550a96ea55e59771312106250a45265ece908dc12e1bbfa28cb8c1e031

Contents?: true

Size: 804 Bytes

Versions: 11

Compression:

Stored size: 804 Bytes

Contents

module EffectivePollsHelper

  # Used by admin/polls form
  def effective_polls_audience_scope_collection
    # Normalize the collection into [[label, value], [label, value]]
    scopes = Array(EffectivePolls.audience_user_scopes).map do |key, value|
      (key.present? && value.present?) ? [key, value] : [key.to_s.titleize, key]
    end

    # Makes sure the User model responds to all values
    scopes.each do |_, scope|
      unless defined?(User) && User.respond_to?(scope)
        raise("invalid effective_polls config.audience_user_scopes value. The user model must respond to the scope User.#{scope}")
      end
    end

    # Append the number of users in this scope
    scopes.map! do |label, scope|
      ["#{label} (#{pluralize(User.send(scope).count, 'user')})", scope]
    end
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
effective_polls-0.3.0 app/helpers/effective_polls_helper.rb
effective_polls-0.2.0 app/helpers/effective_polls_helper.rb
effective_polls-0.1.6 app/helpers/effective_polls_helper.rb
effective_polls-0.1.5 app/helpers/effective_polls_helper.rb
effective_polls-0.1.4 app/helpers/effective_polls_helper.rb
effective_polls-0.1.3 app/helpers/effective_polls_helper.rb
effective_polls-0.1.2 app/helpers/effective_polls_helper.rb
effective_polls-0.1.1 app/helpers/effective_polls_helper.rb
effective_polls-0.1.0 app/helpers/effective_polls_helper.rb
effective_polls-0.0.2 app/helpers/effective_polls_helper.rb
effective_polls-0.0.1 app/helpers/effective_polls_helper.rb