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

Methods included from Initializer

extended

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.



21
22
23
24
# File 'lib/rom/struct_compiler.rb', line 21

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rom/struct_compiler.rb', line 30

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