Module: Foobara::TypeDeclarations
- Defined in:
- foobara-0.0.130/projects/type_declarations/src/caster.rb,
foobara-0.0.130/projects/type_declarations/src/processor.rb,
foobara-0.0.130/projects/type_declarations/src/validator.rb,
foobara-0.0.130/projects/type_declarations/src/attributes.rb,
foobara-0.0.130/projects/type_declarations/src/desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/transformer.rb,
foobara-0.0.130/projects/type_declarations/src/type_builder.rb,
foobara-0.0.130/projects/type_declarations/src/dsl/attributes.rb,
foobara-0.0.130/projects/type_declarations/src/error_extension.rb,
foobara-0.0.130/projects/type_declarations/src/with_registries.rb,
foobara-0.0.130/projects/type_declarations/src/element_processor.rb,
foobara-0.0.130/projects/type_declarations/src/type_declarations.rb,
foobara-0.0.130/projects/type_declarations/src/typed_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/sensitive_type_remover.rb,
foobara-0.0.130/projects/type_declarations/src/type_declaration_error.rb,
foobara-0.0.130/projects/type_declarations/src/type_declaration_handler.rb,
foobara-0.0.130/projects/type_declarations/lib/foobara/type_declarations.rb,
foobara-0.0.130/projects/type_declarations/src/type_declaration_validator.rb,
foobara-0.0.130/projects/type_declarations/src/sensitive_type_removers/array.rb,
foobara-0.0.130/projects/type_declarations/src/sensitive_value_removers/array.rb,
foobara-0.0.130/projects/type_declarations/src/type_declaration_handler_registry.rb,
foobara-0.0.130/projects/type_declarations/src/sensitive_type_removers/attributes.rb,
foobara-0.0.130/projects/type_declarations/src/remove_sensitive_values_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/sensitive_value_removers/attributes.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_array_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/symbolize_private.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/hash_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_validator.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/valid_attribute_names.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/model_class_desugarizer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/primary_key_desugarizer.rb,
foobara-0.0.130/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/array_with_symbolic_elements.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_present.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/attributes_handler_desugarizer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_is_symbol.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/hash_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/to_type_transformer.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/move_private_from_element_types_to_root.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/model_class_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/primary_key_desugarizer.rb,
foobara-0.0.130/projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/validate_primary_key_references_attribute.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_present.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/attributes_handler_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_is_symbol.rb,
foobara-0.0.130/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb,
foobara-0.0.130/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/validate_primary_key_references_attribute.rb
Defined Under Namespace
Modules: Attributes, Dsl, ErrorExtension, Handlers, Mode, SensitiveTypeRemovers, SensitiveValueRemovers, WithRegistries
Classes: Caster, Desugarizer, ElementProcessor, Processor, RemoveSensitiveValuesTransformer, SensitiveTypeRemover, ToTypeTransformer, Transformer, TypeBuilder, TypeDeclarationError, TypeDeclarationHandler, TypeDeclarationHandlerRegistry, TypeDeclarationValidator, TypedTransformer, Validator
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.validate_error_context_enabled ⇒ Object
Returns the value of attribute validate_error_context_enabled.
4
5
6
|
# File 'foobara-0.0.130/projects/type_declarations/src/error_extension.rb', line 4
def validate_error_context_enabled
@validate_error_context_enabled
end
|
Class Method Details
.args_to_type_declaration(*args, &block) ⇒ Object
TODO: relocate these to a different file
7
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
40
41
42
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_builder.rb', line 7
def args_to_type_declaration(*args, &block)
if block
unless args.empty?
raise ArgumentError, "Cannot provide both block and declaration"
end
block
else
case args.size
when 0
raise ArgumentError, "expected 1 argument or a block but got 0 arguments and no block"
when 1
args.first
else
type, *symbolic_processors, processor_data = args
if !symbolic_processors.empty?
symbolic_processors = symbolic_processors.to_h { |symbol| [symbol, true] }
if processor_data.is_a?(::Hash) && !processor_data.empty?
processor_data.merge(symbolic_processors)
else
symbolic_processors
end
elsif processor_data.is_a?(::Hash)
processor_data
else
{ processor_data.to_sym => true }
end.merge(type:)
end
end
end
|
.capture_current_namespaces ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'foobara-0.0.130/projects/type_declarations/lib/foobara/type_declarations.rb', line 127
def capture_current_namespaces
@original_scoped = Namespace.global.foobara_registry.all_scoped.dup
@original_children = Namespace.global.foobara_children.dup
if GlobalDomain.const_defined?(:Types, false)
@original_foobara_lowercase_constants =
GlobalDomain::Types.instance_variable_get(:@foobara_lowercase_constants).dup
end
end
|
.declarations_equal?(declaration1, declaration2) ⇒ Boolean
TODO: we should desugarize these but can’t because of a bug where desugarizing entities results in creating the entity class in memory, whoops.
97
98
99
100
101
102
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 97
def declarations_equal?(declaration1, declaration2)
declaration1 = declaration1.reject { |(k, _v)| k.to_s.start_with?("_") }.to_h
declaration2 = declaration2.reject { |(k, _v)| k.to_s.start_with?("_") }.to_h
declaration1 == declaration2
end
|
.foobara_manifest_context ⇒ Object
104
105
106
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 104
def foobara_manifest_context
Thread.inheritable_thread_local_var_get("foobara_manifest_context")
end
|
.global_type_declaration_handler_registry ⇒ Object
15
16
17
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 15
def global_type_declaration_handler_registry
GlobalDomain.foobara_type_builder.type_declaration_handler_registry
end
|
.install! ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'foobara-0.0.130/projects/type_declarations/lib/foobara/type_declarations.rb', line 81
def install!
capture_current_namespaces
reset_all
Foobara::Error.include(ErrorExtension)
Value::Processor::Casting::CannotCastError.singleton_class.define_method :context_type_declaration do
{
cast_to: :duck,
value: :duck,
attribute_name: :symbol
}
end
Value::Processor::Selection::NoApplicableProcessorError.singleton_class.define_method(
:context_type_declaration
) do
{
processor_names: [:symbol],
value: :duck
}
end
Value::Processor::Selection::MoreThanOneApplicableProcessorError.singleton_class.define_method(
:context_type_declaration
) do
{
applicable_processor_names: [:symbol],
processor_names: [:symbol],
value: :duck
}
end
Value::DataError.singleton_class.define_method :context_type_declaration do
{
attribute_name: :symbol,
value: :duck
}
end
end
|
.manifest_context_set?(context_item) ⇒ Boolean
123
124
125
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 123
def manifest_context_set?(context_item)
foobara_manifest_context&.key?(context_item)
end
|
.new_project_added(_project) ⇒ Object
123
124
125
|
# File 'foobara-0.0.130/projects/type_declarations/lib/foobara/type_declarations.rb', line 123
def new_project_added(_project)
capture_current_namespaces
end
|
.register_sensitive_type_remover(sensitive_type_remover) ⇒ Object
23
24
25
26
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 23
def register_sensitive_type_remover(sensitive_type_remover)
handler = sensitive_type_remover.handler
sensitive_type_removers[handler.class.name] = sensitive_type_remover
end
|
.register_sensitive_value_remover(handler, sensitive_value_remover) ⇒ Object
TODO: since these are dealing with values instead of declarations maybe this should live somewhere else?
45
46
47
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 45
def register_sensitive_value_remover(handler, sensitive_value_remover)
sensitive_value_removers[handler.class.name] = sensitive_value_remover
end
|
.register_type_declaration(type_declaration_handler) ⇒ Object
19
20
21
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 19
def register_type_declaration(type_declaration_handler)
global_type_declaration_handler_registry.register(type_declaration_handler)
end
|
.remove_sensitive_types(strict_type_declaration) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 32
def remove_sensitive_types(strict_type_declaration)
handler = GlobalDomain.foobara_type_builder.type_declaration_handler_for(strict_type_declaration)
sensitive_type_remover = sensitive_type_removers[handler.class.name]
if sensitive_type_remover
sensitive_type_remover.process_value!(strict_type_declaration)
else
strict_type_declaration
end
end
|
.reset_all ⇒ Object
4
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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'foobara-0.0.130/projects/type_declarations/lib/foobara/type_declarations.rb', line 4
def reset_all
Foobara::Domain::DomainModuleExtension.all.each do |domain|
var = "@foobara_type_builder"
if domain.instance_variable_defined?(var)
domain.remove_instance_variable(var)
end
end
Util.descendants(Error).each do |error_class|
if error_class.instance_variable_defined?(:@context_type)
error_class.remove_instance_variable(:@context_type)
end
end
[
"foobara_children",
"foobara_registry",
"foobara_type_builder"
].each do |var_name|
var_name = "@#{var_name}"
[
Namespace.global,
Foobara::GlobalOrganization,
Foobara::GlobalDomain,
Domain,
Command,
Types::Type,
Value::Processor,
Error
].each do |klass|
klass.remove_instance_variable(var_name) if klass.instance_variable_defined?(var_name)
end
end
if GlobalDomain.const_defined?(:Types, false)
GlobalDomain::Types.instance_variable_set(
:@foobara_lowercase_constants,
@original_foobara_lowercase_constants || []
)
GlobalDomain.send(:remove_const, :Types)
end
@original_scoped.each do |scoped|
Namespace.global.foobara_register(scoped)
end
@original_children.each do |child|
Namespace.global.foobara_children << child
end
GlobalDomain.foobara_parent_namespace = GlobalOrganization
GlobalOrganization.foobara_register(GlobalDomain)
register_type_declaration(Handlers::RegisteredTypeDeclaration.new)
register_type_declaration(Handlers::ExtendRegisteredTypeDeclaration.new)
array_handler = Handlers::ExtendArrayTypeDeclaration.new
register_type_declaration(array_handler)
register_type_declaration(Handlers::ExtendAssociativeArrayTypeDeclaration.new)
attributes_handler = Handlers::ExtendAttributesTypeDeclaration.new
register_type_declaration(attributes_handler)
register_type_declaration(Handlers::ExtendTupleTypeDeclaration.new)
@sensitive_type_removers = nil
register_sensitive_type_remover(SensitiveTypeRemovers::Attributes.new(attributes_handler))
register_sensitive_value_remover(attributes_handler, SensitiveValueRemovers::Attributes)
register_sensitive_type_remover(SensitiveTypeRemovers::Array.new(array_handler))
register_sensitive_value_remover(array_handler, SensitiveValueRemovers::Array)
Foobara::AttributesTransformers::Reject.foobara_unregister_all
Foobara::AttributesTransformers::Only.foobara_unregister_all
end
|
.sensitive_type_removers ⇒ Object
28
29
30
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 28
def sensitive_type_removers
@sensitive_type_removers ||= {}
end
|
.sensitive_value_remover_class_for_type(type) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 53
def sensitive_value_remover_class_for_type(type)
handler = GlobalDomain.foobara_type_builder.type_declaration_handler_for(type.declaration_data)
remover_class = sensitive_value_removers[handler.class.name]
unless remover_class
raise "No sensitive value remover found for #{type.declaration_data}"
end
remover_class
end
|
.sensitive_value_removers ⇒ Object
49
50
51
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 49
def sensitive_value_removers
@sensitive_value_removers ||= {}
end
|
.strict ⇒ Object
66
67
68
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 66
def strict(&)
using_mode(Mode::STRICT, &)
end
|
.strict? ⇒ Boolean
83
84
85
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 83
def strict?
foobara_manifest_context_mode == Mode::STRICT
end
|
.strict_stringified ⇒ Object
70
71
72
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 70
def strict_stringified(&)
using_mode(Mode::STRICT_STRINGIFIED, &)
end
|
.strict_stringified? ⇒ Boolean
87
88
89
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 87
def strict_stringified?
foobara_manifest_context_mode == Mode::STRICT_STRINGIFIED
end
|
.stringified ⇒ Object
74
75
76
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 74
def stringified(&)
using_mode(Mode::STRINGIFIED, &)
end
|
.stringified? ⇒ Boolean
91
92
93
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 91
def stringified?
foobara_manifest_context_mode == Mode::STRINGIFIED
end
|
.using_mode(new_mode) ⇒ Object
TODO: use manifest context instead
79
80
81
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 79
def using_mode(new_mode, &)
with_manifest_context(mode: new_mode, &)
end
|
.validate_error_context_enabled? ⇒ Boolean
6
7
8
|
# File 'foobara-0.0.130/projects/type_declarations/src/error_extension.rb', line 6
def validate_error_context_enabled?
validate_error_context_enabled
end
|
.with_manifest_context(context) ⇒ Object
127
128
129
130
131
132
133
134
135
136
|
# File 'foobara-0.0.130/projects/type_declarations/src/type_declarations.rb', line 127
def with_manifest_context(context)
old_context = foobara_manifest_context
begin
new_context = (old_context || {}).merge(context)
Thread.inheritable_thread_local_var_set("foobara_manifest_context", new_context)
yield
ensure
Thread.inheritable_thread_local_var_set("foobara_manifest_context", old_context)
end
end
|
.with_validate_error_context_disabled ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'foobara-0.0.130/projects/type_declarations/src/error_extension.rb', line 10
def with_validate_error_context_disabled
old_enabled = validate_error_context_enabled
begin
self.validate_error_context_enabled = false
yield
ensure
self.validate_error_context_enabled = old_enabled
end
end
|