Class: Foobara::TypeDeclarations::Handlers::ExtendRegisteredTypeDeclaration::ToTypeTransformer

Inherits:
RegisteredTypeDeclaration::ToTypeTransformer show all
Defined in:
foobara-0.0.110/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb

Overview

TODO: make a quick way to convert a couple simple procs into a transformer

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods inherited from RegisteredTypeDeclaration::ToTypeTransformer

#registered_type, #target_classes, #type_symbol

Methods inherited from ToTypeTransformer

#always_applicable?

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods inherited from Value::Transformer

create, error_classes, foobara_manifest, #process_value, subclass

Methods inherited from Value::Processor

#always_applicable?, #applicable?, #attribute_name, #build_error, default_declaration_data, #dup_processor, error_class, 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, #process_value!, processor_name, requires_declaration_data?, requires_parent_declaration_data?, #respond_to_missing?, #runner, 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_keysObject



76
77
78
# File 'foobara-0.0.110/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb', line 76

def non_processor_keys
  %i[type _desugarized description sensitive sensitive_exposed]
end

#transform(strict_type_declaration) ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'foobara-0.0.110/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb', line 10

def transform(strict_type_declaration)
  # TODO: maybe cache this stuff??
  base_type = super

  casters = []
  transformers = []
  validators = []
  element_processors = []

  additional_processors_to_apply = strict_type_declaration.except(*non_processor_keys)

  # TODO: validate the name
  additional_processors_to_apply.each_pair do |processor_symbol, declaration_data|
    processor_class = base_type.find_supported_processor_class(processor_symbol)
    processor = processor_class.new_with_agnostic_args(
      declaration_data:,
      parent_declaration_data: strict_type_declaration
    )

    category = case processor
               when Value::Caster
                 casters
               when Value::Validator
                 validators
               when Value::Transformer
                 transformers
               when Types::ElementProcessor
                 element_processors
               else
                 # TODO: add validator that these are all fine so we don't have to bother here...
                 # :nocov:
                 raise "Not sure where to put #{processor}"
                 # :nocov:
               end

    category << processor
  end

  sensitive = strict_type_declaration[:sensitive]
  sensitive_exposed = strict_type_declaration[:sensitive_exposed]

  type_class.new(
    strict_type_declaration,
    base_type:,
    description: strict_type_declaration[:description],
    casters:,
    transformers:,
    validators:,
    element_processors:,
    # TODO: can't we just set this to [] here??
    target_classes: target_classes(strict_type_declaration),
    name: type_name(strict_type_declaration),
    sensitive:,
    sensitive_exposed:
  )
end

#type_classObject



67
68
69
# File 'foobara-0.0.110/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb', line 67

def type_class
  Types::Type
end

#type_name(strict_type_declaration) ⇒ Object

TODO: test that registering a custom type sets its name



72
73
74
# File 'foobara-0.0.110/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb', line 72

def type_name(strict_type_declaration)
  "Anonymous #{strict_type_declaration[:type]} extension"
end