<commit_before># coding: utf-8
module ActiveScaffold
  module Helpers
    # Helpers that assist with the rendering of a List Column
    module ListColumnHelpers
      def get_column_value(record, column)
        # check for an override helper
        value = if column_override? column
          # we only pass the record as the argument. we previously also passed the formatted_value,
          # but <NAME> pointed out that prohibited the usage of overrides to improve on the
          # performance of our default formatting. see issue #138.
          send(column_override(column), record)
        # second, check if the dev has specified a valid list_ui for this column
        elsif column.list_ui and override_column_ui?(column.list_ui)
          send(override_column_ui(column.list_ui), column, record)

        elsif column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name)
          active_scaffold_inplace_edit(record, column)
        elsif column.column and override_column_ui?(column.column.type)
          send(override_column_ui(column.column.type), column, record)
        else
          value = record.send(column.name)

          if value && column.association
            associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association
            # we are not using eager loading, cache firsts records in order not to query the database in a future
            unless value.loaded?
              # load at least one record, is needed for column_empty? and checking permissions
              if column.associated_limit.nil?
                Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
              else
                record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max, :select => column.select_columns)
              end
            end
          end

          if column.association.nil? or column_empty?(value)
            formatted_value = clean_column_value(format_value(value, column.options))
          else
            case column.association.macro
              when :has_one, :belongs_to
                formatted_value = clean_column_value(format_value(value.to_label))

              when :has_many, :has_and_belongs_to_many
                if column.associated_limit.nil?
                  firsts = value.collect { |v| v.to_label }
                else
                  firsts = value.first(column.associated_limit)
                  firsts.collect! { |v| v.to_label }
                  firsts[column.associated_limit] = '…' if associated_size > column.associated_limit
                end
                if column.associated_limit == 0
                  formatted_value = associated_size if column.associated_number?
                else
                  formatted_value = clean_column_value(format_value(firsts.join(', ')))
                  formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and associated_size > column.associated_limit
                end
                formatted_value
            end
          end

          formatted_value
        end

        value = '&nbsp;' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6
        return value
      end

      # TODO: move empty_field_text and &nbsp; logic in here?
      # TODO: move active_scaffold_inplace_edit in here?
      # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link.<commit_msg>Fix show associations in list with associated_number disabled<commit_after># coding: utf-8
module ActiveScaffold
  module Helpers
    # Helpers that assist with the rendering of a List Column
    module ListColumnHelpers
      def get_column_value(record, column)
        # check for an override helper
        value = if column_override? column
          # we only pass the record as the argument. we previously also passed the formatted_value,
          # but <NAME> pointed out that prohibited the usage of overrides to improve on the
          # performance of our default formatting. see issue #138.
          send(column_override(column), record)
        # second, check if the dev has specified a valid list_ui for this column
        elsif column.list_ui and override_column_ui?(column.list_ui)
          send(override_column_ui(column.list_ui), column, record)

        elsif column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name)
          active_scaffold_inplace_edit(record, column)
        elsif column.column and override_column_ui?(column.column.type)
          send(override_column_ui(column.column.type), column, record)
        else
          value = record.send(column.name)

          if value && column.association
            associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association
            # we are not using eager loading, cache firsts records in order not to query the database in a future
            unless value.loaded?
              # load at least one record, is needed for column_empty? and checking permissions
              if column.associated_limit.nil?
                Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
              else
                record.send(column.name).target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns)
              end
            end
          end

          if column.association.nil? or column_empty?(value)
            formatted_value = clean_column_value(format_value(value, column.options))
          else
            case column.association.macro
              when :has_one, :belongs_to
                formatted_value = clean_column_value(format_value(value.to_label))

              when :has_many, :has_and_belongs_to_many
                if column.associated_limit.nil?
                  firsts = value.collect { |v| v.to_label }
                else
                  firsts = value.first(column.associated_limit)
                  firsts.collect! { |v| v.to_label }
                  firsts[column.associated_limit] = '…' if value.size > column.associated_limit
                end
                if column.associated_limit == 0
                  formatted_value = associated_size if column.associated_number?
                else
                  formatted_value = clean_column_value(format_value(firsts.join(', ')))
                  formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit
                end
                formatted_value
            end
          end

          formatted_value
        end

        value = '&nbsp;' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6
        return value
      end

      # TODO: move empty_field_text and &nbsp; logic in here?
      # TODO: move active_scaffold_inplace_edit in here?
      # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link.
{'fraction_non_alphanumeric': 0.06790873498042392, 'fraction_numerical': 0.0018901039557175645, 'mean_word_length': 2.295373665480427, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1784350', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1857, 'n_words': 602}