Sha256: b2bb636c63d8373522a6f2511df314ef660ed265ee1d322334b9000faf4f8afb
Contents?: true
Size: 904 Bytes
Versions: 27
Compression:
Stored size: 904 Bytes
Contents
# frozen_string_literal: true module Motor module BuildSchema module FindSearchableColumns SELECT_COLUMNS_AMOUNT = 2 COLUMN_TYPES = BuildSchema::SEARCHABLE_COLUMN_TYPES module_function def call(model) columns = find_searchable_columns(model) selected_columns = columns.grep(BuildSchema::FindDisplayColumn::DISPLAY_NAME_REGEXP).presence selected_columns ||= columns.first(SELECT_COLUMNS_AMOUNT) ([model.primary_key] + selected_columns).compact.sort end def find_searchable_columns(model) model.columns.map do |column| next unless column.type.in?(COLUMN_TYPES) next if column.respond_to?(:array?) && column.array? next if model.validators_on(column.name).any?(ActiveModel::Validations::InclusionValidator) column.name end.compact end end end end
Version data entries
27 entries across 27 versions & 1 rubygems