Class: ROM::StructCompiler Private

Inherits:
Dry::Types::Compiler
  • Object
show all
Extended by:
Initializer
Defined in:
lib/rom/struct_compiler.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.

Instance Method Summary collapse

Constructor Details

#initializeStructCompiler

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


26
27
28
29
# File 'lib/rom/struct_compiler.rb', line 26

def initialize(*)
  super
  @cache = cache.namespaced(:structs)
end

Instance Method Details

#call(*args) ⇒ Object Also known as: []

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.

Build a struct class based on relation header ast


35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rom/struct_compiler.rb', line 35

def call(*args)
  cache.fetch_or_store(args) do
    name, header, ns = args
    attributes = header.map(&method(:visit)).compact

    if attributes.empty?
      ROM::OpenStruct
    else
      build_class(name, ROM::Struct, ns) do |klass|
        klass.attributes(attributes.to_h)
      end
    end
  end
end