Sha256: 45e6d40c2c84c5afc1728e04c9d372b698ddb619d5f1e16b369da9cc6f02abb4
Contents?: true
Size: 1.21 KB
Versions: 12
Compression:
Stored size: 1.21 KB
Contents
# frozen_string_literal: true require 'set' module ROM module SQL class Schema < ROM::Schema # @api public class IndexDSL # < BasicObject extend Initializer option :attr_class attr_reader :registry # @api private def initialize(*, &block) super @registry = [] instance_exec(&block) end ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true) # @api public def index(*attributes, **options) registry << [attributes, options] end # @api private def call(schema_name, attrs) attributes = attrs.map do |attr| attr_class.new(attr[:type], **(attr[:options] || {})).meta(source: schema_name) end registry.map { |attr_names, options| build_index(attributes, attr_names, options) }.to_set end private # @api private def build_index(attributes, attr_names, options) index_attributes = attr_names.map do |name| attributes.find { |a| a.name == name }.unwrap end Index.new(index_attributes, **options) end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems