Class: Foobara::ActiveRecordType::ExtendActiveRecordTypeDeclaration::ToTypeTransformer

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods inherited from TypeDeclarations::Handlers::ExtendRegisteredTypeDeclaration::ToTypeTransformer

#transform

Methods inherited from TypeDeclarations::Handlers::RegisteredTypeDeclaration::ToTypeTransformer

#registered_type, #transform

Methods inherited from TypeDeclarations::ToTypeTransformer

#always_applicable?

Methods included from TypeDeclarations::WithRegistries

#handler_for_class, #lookup_absolute_type!, #lookup_type, #lookup_type!, #type_declaration_handler_for, #type_for_declaration, #type_registered?

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods inherited from Value::Transformer

create, error_classes, foobara_manifest, subclass, #transform

Methods inherited from Value::Processor

#always_applicable?, #applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, #error_class, error_classes, #error_classes, #error_context, #error_message, #error_path, foobara_manifest, #foobara_manifest, #initialize, #inspect, instance, #method_missing, #name, new_with_agnostic_args, #possible_errors, #priority, #process_outcome, #process_outcome!, #process_value!, processor_name, requires_declaration_data?, #requires_declaration_data?, requires_parent_declaration_data?, #requires_parent_declaration_data?, #respond_to_missing?, #runner, symbol, #symbol

Methods included from IsManifestable

#foobara_domain, #foobara_manifest, #foobara_organization, #scoped_clear_caches

Constructor Details

This class inherits a constructor from Foobara::Value::Processor

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor

Instance Method Details

#non_processor_keys ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'src/extend_active_record_type_declaration/to_type_transformer.rb', line 36

def non_processor_keys
  [
    :primary_key,
    :name,
    :model_class,
    :model_base_class,
    :model_module,
    :attributes_declaration,
    *super
  ]
end

#process_value(strict_declaration_type) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'src/extend_active_record_type_declaration/to_type_transformer.rb', line 5

def process_value(strict_declaration_type)
  super.tap do |outcome|
    if outcome.success?
      type = outcome.result

      active_record_class = type.target_class
      active_record_class.foobara_type = type

      handler = handler_for_class(TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration)
      attributes_type_declaration = type.declaration_data[:attributes_declaration]

      active_record_class.foobara_attributes_type = TypeDeclarations.strict do
        handler.process_value!(TypeDeclaration.new(attributes_type_declaration))
      end

      type.element_types = active_record_class.foobara_attributes_type.element_types
      type_name = type.declaration_data[:name]

      domain = Domain.domain_through_modules(active_record_class)

      type_name = type_name.gsub(/^#{domain.scoped_full_name}::/, "")

      domain.foobara_register_type(type_name, type)
    end
  end
end

#target_classes(strict_type_declaration) ⇒ Object



32
33
34
# File 'src/extend_active_record_type_declaration/to_type_transformer.rb', line 32

def target_classes(strict_type_declaration)
  Object.const_get(strict_type_declaration[:model_class])
end

#type_class ⇒ Object



48
49
50
# File 'src/extend_active_record_type_declaration/to_type_transformer.rb', line 48

def type_class
  Foobara::DetachedEntityType
end

#type_name(strict_type_declaration) ⇒ Object



52
53
54
# File 'src/extend_active_record_type_declaration/to_type_transformer.rb', line 52

def type_name(strict_type_declaration)
  strict_type_declaration[:name]
end