Class: ROM::SQL::Schema::IndexDSL

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Defined in:
lib/rom/sql/schema/index_dsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ IndexDSL

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of IndexDSL.



17
18
19
20
21
22
23
# File 'lib/rom/sql/schema/index_dsl.rb', line 17

def initialize(*, &block)
  super

  @registry = []

  instance_exec(&block)
end

Instance Attribute Details

#registryObject (readonly)



14
15
16
# File 'lib/rom/sql/schema/index_dsl.rb', line 14

def registry
  @registry
end

Instance Method Details

#call(schema_name, attrs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



27
28
29
# File 'lib/rom/sql/schema/index_dsl.rb', line 27

def index(*attributes, **options)
  registry << [attributes, options]
end