Class: ROM::Schema::Inferrer Private

Inherits:
Object
  • Object
show all
Extended by:
Dry::Core::ClassAttributes, Initializer
Defined in:
lib/rom/schema/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

MissingAttributesError =

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.

Class.new(StandardError) do
  def initialize(name, attributes)
    super(
      "Following attributes in #{Relation::Name[name].relation.inspect} schema cannot "\
      "be inferred and have to be defined explicitly: #{attributes.map(&:inspect).join(', ')}"
    )
  end
end
DEFAULT_ATTRIBUTES =

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.

[EMPTY_ARRAY, EMPTY_ARRAY].freeze

Instance Method Summary collapse

Methods included from Initializer

extended

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.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rom/schema/inferrer.rb', line 38

def call(schema, gateway)
  if enabled?
    inferred, missing = attributes_inferrer.(schema, gateway, options)
  else
    inferred, missing = DEFAULT_ATTRIBUTES
  end

  attributes = merge_attributes(schema.attributes, inferred)

  check_all_attributes_defined(schema, attributes, missing)

  { attributes: attributes }
end

#check_all_attributes_defined(schema, all_known, not_inferred) ⇒ 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.



53
54
55
56
57
58
59
# File 'lib/rom/schema/inferrer.rb', line 53

def check_all_attributes_defined(schema, all_known, not_inferred)
  not_defined = not_inferred - all_known.map(&:name)

  if not_defined.size > 0
    raise MissingAttributesError.new(schema.name, not_defined)
  end
end

#merge_attributes(defined, inferred) ⇒ 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.



62
63
64
65
66
# File 'lib/rom/schema/inferrer.rb', line 62

def merge_attributes(defined, inferred)
  defined_names = defined.map(&:name)

  defined + inferred.reject { |attr| defined_names.include?(attr.name) }
end