Class: Foobara::TypeDeclarations::RemoveSensitiveValuesTransformer

Inherits:
TypedTransformer show all
Defined in:
foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Instance Method Summary collapse

Methods inherited from TypedTransformer

#always_applicable?, from, #from_type, #has_from_type?, #has_to_type?, #initialize, #process_value, requires_declaration_data?, requires_parent_declaration_data?, to, #to_type

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

Methods included from Concern

foobara_class_methods_module_for, foobara_concern?, included

Constructor Details

This class inherits a constructor from Foobara::TypeDeclarations::TypedTransformer

Dynamic Method Handling

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

Instance Method Details

#create_all_association_types_in_current_namespace(type) ⇒ Object



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
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 18

def create_all_association_types_in_current_namespace(type)
  already_sanitized = Set.new

  associations = Foobara::DetachedEntity.construct_deep_associations(type)

  associations&.values&.reverse&.each do |entity_type|
    next if already_sanitized.include?(entity_type)

    next if entity_type.sensitive?

    unless entity_type.has_sensitive_types?
      already_sanitized << entity_type
      next
    end

    ns = Namespace.current

    declaration = entity_type.declaration_data
    sanitized_type_declaration = TypeDeclarations.remove_sensitive_types(declaration)

    existing_type = ns.foobara_lookup(
      entity_type.full_type_symbol,
      mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE
    )

    if existing_type
      if existing_type.declaration_data == sanitized_type_declaration
        already_sanitized << entity_type
        already_sanitized << existing_type
        next
      else
        # :nocov:
        raise "Did not expect to be re-sanitizing #{entity_type.full_type_symbol}"
        # :nocov:
      end

    end

    # We want to make sure that any types that change due to having sensitive types
    # has a corresponding registered type in the command registry domain if needed
    # TODO: this all feels so messy and brittle.
    Domain.current.foobara_type_from_declaration(sanitized_type_declaration)

    already_sanitized << entity_type
  end
end

#fromObject



6
7
8
9
10
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 6

def from(...)
  super.tap do
    create_all_association_types_in_current_namespace(from_type)
  end
end

#from_type_declarationObject



69
70
71
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 69

def from_type_declaration
  TypeDeclarations.remove_sensitive_types(to_type.declaration_data)
end

#sanitize_value(type, value) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 79

def sanitize_value(type, value)
  if type.has_sensitive_types?
    sanitized_value = Namespace.use to_type.created_in_namespace do
      remover_class = TypeDeclarations.sensitive_value_remover_class_for_type(type)
      remover = remover_class.new(from: type)
      remover.process_value!(value)
    end

    [sanitized_value, sanitized_value != value]
  else
    [value, false]
  end
end

#toObject



12
13
14
15
16
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 12

def to(...)
  super.tap do
    create_all_association_types_in_current_namespace(to_type)
  end
end

#to_type_declarationObject



65
66
67
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 65

def to_type_declaration
  TypeDeclarations.remove_sensitive_types(from_type.declaration_data)
end

#transform(_value) ⇒ Object



73
74
75
76
77
# File 'foobara-0.2.2/projects/type_declarations/src/remove_sensitive_values_transformer.rb', line 73

def transform(_value)
  # :nocov:
  raise "subclass responsibility"
  # :nocov:
end