Sha256: 312f8fcc113bec649361512cc0cede9c610a1dcf4152806c03d0dee3532ee34f

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 Bytes

Contents

module BlindIndex
  module Extensions
    module TableMetadata
      def resolve_column_aliases(hash)
        new_hash = super
        if has_blind_indexes?
          hash.each do |key, _|
            if (bi = klass.blind_indexes[key])
              new_hash[bi[:bidx_attribute]] = BlindIndex.generate_bidx(new_hash.delete(key), bi)
            end
          end
        end
        new_hash
      end

      # memoize for performance
      def has_blind_indexes?
        unless defined?(@has_blind_indexes)
          @has_blind_indexes = klass.respond_to?(:blind_indexes)
        end
        @has_blind_indexes
      end
    end

    module UniquenessValidator
      def build_relation(klass, table, attribute, value)
        if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
          value = BlindIndex.generate_bidx(value, bi)
          attribute = bi[:bidx_attribute]
        end
        super(klass, table, attribute, value)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blind_index-0.1.0 lib/blind_index/extensions.rb