class ROM::SQL::Schema::IndexDSL

@api public

Attributes

registry[R]

Public Class Methods

new(*, &block) click to toggle source

@api private

Calls superclass method
# File lib/rom/sql/schema/index_dsl.rb, line 17
def initialize(*, &block)
  super

  @registry = []

  instance_exec(&block)
end

Public Instance Methods

call(schema_name, attrs) click to toggle source

@api private

# File lib/rom/sql/schema/index_dsl.rb, line 32
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
index(*attributes, **options) click to toggle source

@api public

# File lib/rom/sql/schema/index_dsl.rb, line 27
def index(*attributes, **options)
  registry << [attributes, options]
end

Private Instance Methods

build_index(attributes, attr_names, options) click to toggle source

@api private

# File lib/rom/sql/schema/index_dsl.rb, line 45
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