Class: ROM::Files::Schema::AttributesInferrer Private

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

Direct Known Subclasses

Extensions::Markup::AttributesInferrer

Constant Summary collapse

KNOWN_COLUMNS =

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.

[ID].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attr_classClass(Files::Attribute) (readonly)

Returns:



43
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 43

option :attr_class, default: -> { self.class.attr_class }

Class Method Details

.[](mime_type) ⇒ AttributesInferrer

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.

Parameters:

  • mime_type (String)

Returns:



37
38
39
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 37

def self.[](mime_type)
  registry[mime_type]
end

.register(type, inferrer) ⇒ AttributesInferrer

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.

Parameters:

Returns:



27
28
29
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 27

def self.register(type, inferrer)
  registry[type] = inferrer
end

.registered?(type) ⇒ Boolean

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:

  • (Boolean)


31
32
33
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 31

def self.registered?(type)
  registry.key?(type)
end

.registryHash{String => AttributesInferrer}

Returns:



20
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 20

defines :registry, :attr_class

Instance Method Details

#build(type, name, schema) ⇒ Files::Attribute

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:



60
61
62
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 60

def build(type, name, schema)
  attr_class.new(type.meta(name: name, source: schema.name))
end

#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.

Parameters:



49
50
51
52
53
54
55
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 49

def call(schema, gateway)
  inferred = infer_attributes(schema, gateway)

  missing = columns - inferred.map { |attr| attr.meta[:name] }

  [inferred, missing]
end

#columnsArray<Symbol>

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:

  • (Array<Symbol>)


65
66
67
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 65

def columns
  KNOWN_COLUMNS
end

#infer_attributes(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.



73
74
75
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 73

def infer_attributes(schema, _gateway)
  [build(Types::Path, ID, schema)]
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.



69
70
71
# File 'lib/rom/files/schema/attributes_inferrer.rb', line 69

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