Class: Foobara::BuiltinTypes::Tuple::SupportedProcessors::ElementTypeDeclarations

Inherits:
TypeDeclarations::ElementProcessor show all
Defined in:
foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb,
foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb,
foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb

Overview

TODO: how to relate size to this? I guess a TypeDeclarationValidator is a good idea here to make sure that element_type_declarations.size matches size if both are present and a Desugarizer that sets them both?

Defined Under Namespace

Modules: TypeDeclarationExtension

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods inherited from Value::Processor

#always_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, #priority, #process_outcome, #process_outcome!, #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

#applicable?(value) ⇒ Boolean

Returns:



8
9
10
11
12
13
14
# File 'foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb', line 8

def applicable?(value)
  # Size mismatch is handled by size validator later so just bail out here since without a correct
  # size we don't really know what to expect to happen if we proceed.
  # TODO: would be nice to have the Size validator run earlier in the process so that we wouldn't have
  # to check this here.
  value.size == element_type_declarations.size
end

#element_typesObject



16
17
18
19
20
# File 'foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb', line 16

def element_types
  @element_types ||= element_type_declarations.map do |type_declaration|
    type_for_declaration(type_declaration)
  end
end

#possible_errorsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb', line 42

def possible_errors
  possibilities = super.dup

  element_types.each.with_index do |element_type, index|
    element_type.possible_errors.each do |possible_error|
      possible_error = possible_error.dup
      possible_error.prepend_path!(index)
      possibilities << possible_error
    end
  end

  possibilities
end

#process_value(array) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'foobara-0.0.110/projects/builtin_types/src/tuple/supported_processors/element_type_declarations.rb', line 22

def process_value(array)
  errors = []

  array.each.with_index do |element, index|
    element_outcome = element_types[index].process_value(element)

    if element_outcome.success?
      array[index] = element_outcome.result
    else
      element_outcome.each_error do |error|
        error.prepend_path!(index)

        errors << error
      end
    end
  end

  Outcome.new(result: array, errors:)
end