Class: ROM::SQL::Schema::AttributesInferrer Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes, Initializer
Defined in:
lib/rom/sql/schema/attributes_inferrer.rb

Overview

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

API:

  • private

Constant Summary collapse

CONSTRAINT_DB_TYPE =

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

API:

  • private

'add_constraint'.freeze

Instance Method Summary collapse

Instance Method Details

#call(schema, gateway) ⇒ 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.

API:

  • private



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rom/sql/schema/attributes_inferrer.rb', line 20

def call(schema, gateway)
  dataset = schema.name.dataset

  columns = filter_columns(gateway.connection.schema(dataset))

  inferred = columns.map do |(name, definition)|
    type = type_builder.(definition)

    attr_class.new(type.meta(source: schema.name), name: name) if type
  end.compact

  missing = columns.map(&:first) - inferred.map { |attr| attr.name }

  [inferred, missing]
end

#filter_columns(schema) ⇒ 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.

API:

  • private



44
45
46
# File 'lib/rom/sql/schema/attributes_inferrer.rb', line 44

def filter_columns(schema)
  schema.reject { |(_, definition)| definition[:db_type] == CONSTRAINT_DB_TYPE }
end

#with(new_options) ⇒ 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.

API:

  • private



39
40
41
# File 'lib/rom/sql/schema/attributes_inferrer.rb', line 39

def with(new_options)
  self.class.new(options.merge(new_options))
end