def count_by column_name, field
      inc = increment_mask_for column_name, field
      only = only_mask_for column_name, field
      # Create super-special-bitfield-grouping-query w/ AREL
      sql = arel_table.
        project("count(#{primary_key}) as #{field}_count, (#{column_name} & #{only})/#{inc} as #{field}").
        group(field).to_sql
      connection.send :select, sql, 'AREL' # Execute the query
    end
def count_by column_name, field
      inc = increment_mask_for column_name, field
      only = only_mask_for column_name, field
      # Create super-special-bitfield-grouping-query w/ AREL
      sql = arel_table.
        project("count(#{primary_key}) as #{field}_count, (#{column_name} & #{only})/#{inc} as #{field}").
        group(field).to_sql
      connection.send :select, sql, 'AREL' # Execute the query
    end
Counts resources grouped by a bitfield

 +count_by :column, :fields

 @example
   user.count_by :counter, :monthly

 @param [ Symbol ] column     name of the column these fields are in
 @param [ Symbol ] field(s)   name of the field(s) to reset