module BlindIndex::Extensions::TableMetadata

Public Instance Methods

has_blind_indexes?() click to toggle source

memoize for performance

# File lib/blind_index/extensions.rb, line 25
def has_blind_indexes?
  unless defined?(@has_blind_indexes)
    @has_blind_indexes = klass.respond_to?(:blind_indexes)
  end
  @has_blind_indexes
end
resolve_column_aliases(hash) click to toggle source
Calls superclass method
# File lib/blind_index/extensions.rb, line 5
def resolve_column_aliases(hash)
  new_hash = super
  if has_blind_indexes?
    hash.each_key do |key|
      if key.respond_to?(:to_sym) && (bi = klass.blind_indexes[key.to_sym]) && !new_hash[key].is_a?(ActiveRecord::StatementCache::Substitute)
        value = new_hash.delete(key)
        new_hash[bi[:bidx_attribute]] =
          if value.is_a?(Array)
            value.map { |v| BlindIndex.generate_bidx(v, **bi) }
          else
            BlindIndex.generate_bidx(value, **bi)
          end
      end
    end
  end
  new_hash
end