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

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.

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.

"add_constraint"

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.



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

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(&: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.



46
47
48
# File 'lib/rom/sql/schema/attributes_inferrer.rb', line 46

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.



41
42
43
# File 'lib/rom/sql/schema/attributes_inferrer.rb', line 41

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