Class: Expressir::Express::Builders::InverseAttrBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/expressir/express/builders/inverse_attr_builder.rb

Overview

Builds inverse_attr nodes.

Instance Method Summary collapse

Instance Method Details

#call(ast_data) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/expressir/express/builders/inverse_attr_builder.rb', line 8

def call(ast_data)
  attr_decl_data = ast_data[:attribute_decl]
  attr = if attr_decl_data.is_a?(Hash)
           Builder.build({ attribute_decl: attr_decl_data })
         end

  type_data = ast_data[:inverse_attr_type]
  type = if type_data.is_a?(Hash)
           Builder.build({ inverse_attr_type: type_data })
         end

  expression = if ast_data[:entity_ref]
                 ref = Builder.build({ entity_ref: ast_data[:entity_ref] })
                 attr_ref = if ast_data[:attribute_ref]
                              Builder.build({ attribute_ref: ast_data[:attribute_ref] })
                            end
                 Expressir::Model::References::AttributeReference.new(ref: ref,
                                                                      attribute: attr_ref)
               else
                 attr_ref_data = ast_data[:attribute_ref]
                 if attr_ref_data
                   Builder.build({ attribute_ref: attr_ref_data })
                 end
               end

  Expressir::Model::Declarations::InverseAttribute.new(
    id: attr&.id,
    supertype_attribute: attr&.supertype_attribute,
    type: type,
    expression: expression,
  )
end