foobara 0.0.141 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +23 -0
- data/projects/builtin_types/lib/foobara/builtin_types.rb +1 -0
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_defaults_from_element_types_to_root.rb +9 -2
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/desugarizers/symbolize_defaults.rb +1 -1
- data/projects/builtin_types/src/attributes/supported_transformers/defaults/type_declaration_extension/extend_attributes_type_declaration/type_declaration_validators/hash_with_symbolic_keys.rb +1 -1
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/alphabetize_required.rb +5 -5
- data/projects/builtin_types/src/attributes/supported_validators/required/type_declaration_extension/extend_attributes_type_declaration/desugarizers/move_required_from_element_types_to_root.rb +12 -2
- data/projects/builtin_types/src/builtin_types.rb +1 -1
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_desugarizer.rb +10 -2
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/class_type_desugarizer.rb +7 -2
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_class_desugarizer.rb +3 -4
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/instance_of_symbol_desugarizer.rb +3 -4
- data/projects/builtin_types/src/duck/supported_validators/instance_of/type_declaration_extension/extend_registered_type_declaration/type_declaration_validators/is_valid_class.rb +1 -1
- data/projects/builtin_types/src/duck/supported_validators/instance_of.rb +1 -0
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/cast_one_of.rb +4 -3
- data/projects/builtin_types/src/duck/supported_validators/one_of/type_declaration_extension/extend_registered_type_declaration/desugarizers/module_desugarizer.rb +3 -3
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/desugarizers/set_size.rb +1 -1
- data/projects/builtin_types/src/tuple/supported_processors/element_type_declarations/type_declaration_extension/extend_tuple_type_declaration/type_declaration_validators/size_matches.rb +2 -4
- data/projects/command/src/command_pattern_implementation/concerns/inputs_type.rb +12 -12
- data/projects/command/src/command_pattern_implementation/concerns/reflection.rb +4 -2
- data/projects/command/src/command_pattern_implementation/concerns/result_type.rb +0 -4
- data/projects/command_connectors/src/command_connector.rb +6 -6
- data/projects/command_connectors/src/command_registry.rb +7 -4
- data/projects/command_connectors/src/transformed_command.rb +22 -8
- data/projects/command_connectors/src/transformers/auth_errors_transformer.rb +1 -0
- data/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb +4 -0
- data/projects/common/src/error_collection.rb +1 -1
- data/projects/detached_entity/src/concerns/types.rb +7 -1
- data/projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/model_instance_is_valid.rb +1 -1
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/hash_desugarizer.rb +6 -9
- data/projects/detached_entity/src/extensions/type_declarations/handlers/extend_detached_entity_type_declaration/primary_key_desugarizer.rb +2 -1
- data/projects/domain/src/domain_module_extension.rb +12 -4
- data/projects/entity/src/concerns/types.rb +6 -1
- data/projects/foobara/lib/foobara/all.rb +4 -4
- data/projects/manifest/src/foobara/manifest/type.rb +11 -2
- data/projects/manifest/src/foobara/manifest/type_declaration.rb +46 -2
- data/projects/model/src/concerns/aliases.rb +8 -0
- data/projects/model/src/concerns/reflection.rb +2 -2
- data/projects/model/src/concerns/types.rb +35 -20
- data/projects/model/src/extensions/builtin_types/model/validators/model_instance_is_valid.rb +12 -8
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/array_with_symbolic_elements.rb +1 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/attributes_handler_desugarizer.rb +15 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/delegates_desugarizer.rb +7 -5
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/hash_desugarizer.rb +4 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb +0 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/move_private_from_element_types_to_root.rb +28 -9
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/symbolize_private.rb +8 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb +4 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration.rb +14 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/hash_desugarizer.rb +8 -9
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/model_class_type_desugarizer.rb +6 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/mutable_validator.rb +5 -2
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/normalize_mutable_attributes_desugarizer.rb +8 -7
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration/to_type_transformer.rb +4 -1
- data/projects/model/src/extensions/type_declarations/handlers/extend_registered_model_type_declaration.rb +20 -5
- data/projects/model/src/extensions/type_declarations/handlers/registered_type_declaration/model_class_desugarizer.rb +23 -5
- data/projects/model/src/extensions/type_declarations/lazy_element_types/model.rb +18 -0
- data/projects/model_attribute_helpers/src/attribute_helpers.rb +44 -26
- data/projects/namespace/src/is_namespace.rb +93 -49
- data/projects/namespace/src/namespace/lookup_mode.rb +13 -2
- data/projects/namespace/src/namespace_helpers.rb +1 -0
- data/projects/namespace/src/prefixless_registry.rb +2 -0
- data/projects/persistence/src/entity_base/transaction/concerns/state_transitions.rb +20 -1
- data/projects/persistence/src/entity_base/transaction.rb +14 -11
- data/projects/persistence/src/entity_base/transaction_table.rb +10 -49
- data/projects/persistence/src/entity_base.rb +39 -0
- data/projects/persistence/src/persistence.rb +4 -0
- data/projects/type_declarations/src/attributes.rb +15 -9
- data/projects/type_declarations/src/attributes_transformers/from_yaml.rb +1 -1
- data/projects/type_declarations/src/desugarizer_pipeline.rb +9 -0
- data/projects/type_declarations/src/dsl/attributes.rb +14 -5
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb +24 -4
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/element_type_declaration_desugarizer.rb +23 -9
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb +3 -7
- data/projects/type_declarations/src/handlers/extend_array_type_declaration/type_set_to_array_desugarizer.rb +15 -4
- data/projects/type_declarations/src/handlers/extend_array_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/key_type_declaration_desugarizer.rb +48 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/to_type_transformer.rb +3 -11
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration/value_type_declaration_desugarizer.rb +51 -0
- data/projects/type_declarations/src/handlers/extend_associative_array_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb +1 -1
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/element_type_declarations_desugarizer.rb +17 -7
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/hash_desugarizer.rb +16 -19
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/to_type_transformer.rb +3 -6
- data/projects/type_declarations/src/handlers/extend_attributes_type_declaration.rb +13 -2
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration/to_type_transformer.rb +3 -3
- data/projects/type_declarations/src/handlers/extend_registered_type_declaration.rb +16 -4
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/array_desugarizer.rb +20 -6
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration/to_type_transformer.rb +3 -9
- data/projects/type_declarations/src/handlers/extend_tuple_type_declaration.rb +12 -2
- data/projects/type_declarations/src/handlers/registered_type_declaration/to_type_transformer.rb +7 -9
- data/projects/type_declarations/src/handlers/registered_type_declaration.rb +22 -7
- data/projects/type_declarations/src/lazy_element_types/array.rb +19 -0
- data/projects/type_declarations/src/lazy_element_types/attributes.rb +27 -0
- data/projects/type_declarations/src/lazy_element_types/hash.rb +38 -0
- data/projects/type_declarations/src/lazy_element_types/tuple.rb +23 -0
- data/projects/type_declarations/src/sensitive_type_remover.rb +6 -1
- data/projects/type_declarations/src/sensitive_type_removers/attributes.rb +2 -0
- data/projects/type_declarations/src/type_builder.rb +46 -21
- data/projects/type_declarations/src/type_declaration.rb +295 -0
- data/projects/type_declarations/src/type_declaration_handler.rb +10 -11
- data/projects/type_declarations/src/type_declarations.rb +12 -5
- data/projects/types/src/type.rb +26 -4
- data/projects/value/src/mutator.rb +1 -4
- data/projects/value/src/processor/casting.rb +7 -2
- data/projects/value/src/processor/pipeline.rb +9 -1
- data/projects/value/src/processor.rb +0 -2
- data/projects/value/src/transformer.rb +1 -3
- data/projects/value/src/validator.rb +0 -2
- data/projects/weak_object_set/src/weak_object_set.rb +2 -0
- metadata +24 -21
- data/projects/type_declarations/src/handlers/registered_type_declaration/desugarizer_metadata_cleanup_desugarizer.rb +0 -29
- data/projects/type_declarations/src/handlers/registered_type_declaration/short_type_name_desugarizer.rb +0 -63
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_desugarizer.rb +0 -32
- data/projects/type_declarations/src/handlers/registered_type_declaration/strict_stringified_desugarizer.rb +0 -39
- data/projects/type_declarations/src/handlers/registered_type_declaration/symbol_desugarizer.rb +0 -30
- data/projects/type_declarations/src/handlers/registered_type_declaration/type_desugarizer.rb +0 -24
@@ -62,7 +62,20 @@ module Foobara
|
|
62
62
|
# :nocov:
|
63
63
|
end
|
64
64
|
|
65
|
-
tables[entity_class]
|
65
|
+
table = tables[entity_class]
|
66
|
+
|
67
|
+
if table
|
68
|
+
table
|
69
|
+
else
|
70
|
+
if defined?(@ordered_tables)
|
71
|
+
# TODO: test this path
|
72
|
+
# :nocov:
|
73
|
+
remove_instance_variable(:@ordered_tables)
|
74
|
+
# :nocov:
|
75
|
+
end
|
76
|
+
|
77
|
+
tables[entity_class] = TransactionTable.new(self, entity_class)
|
78
|
+
end
|
66
79
|
end
|
67
80
|
|
68
81
|
def updated(record)
|
@@ -149,16 +162,6 @@ module Foobara
|
|
149
162
|
table_for(entity).track_created(entity)
|
150
163
|
end
|
151
164
|
|
152
|
-
def created?(record)
|
153
|
-
table_for(record).created?(record)
|
154
|
-
end
|
155
|
-
|
156
|
-
# WARNING! this seems to bypass validations, hmmm....
|
157
|
-
def flush_created_record!(record)
|
158
|
-
table_for(record).flush_created_record!(record)
|
159
|
-
end
|
160
|
-
|
161
|
-
# convenience method...
|
162
165
|
def perform(&)
|
163
166
|
entity_base.using_transaction(self, &)
|
164
167
|
end
|
@@ -642,11 +642,12 @@ module Foobara
|
|
642
642
|
|
643
643
|
def flush_created!
|
644
644
|
marked_created.each do |record|
|
645
|
-
flush_created_associations!(record)
|
646
|
-
|
647
645
|
# TODO: do this in bulk
|
648
646
|
attributes = entity_attributes_crud_driver_table.insert(to_persistable(record))
|
649
|
-
|
647
|
+
primary_key_attribute = entity_class.primary_key_attribute
|
648
|
+
primary_key = attributes[primary_key_attribute]
|
649
|
+
|
650
|
+
record.write_attributes_without_callbacks(primary_key_attribute => primary_key)
|
650
651
|
|
651
652
|
# we need to update finding the tracked object by key and removing/reading it seems to be the simplest
|
652
653
|
# way to accomplish that at the moment
|
@@ -660,48 +661,10 @@ module Foobara
|
|
660
661
|
marked_created.clear
|
661
662
|
end
|
662
663
|
|
663
|
-
def flush_created_record!(record)
|
664
|
-
flush_created_associations!(record)
|
665
|
-
|
666
|
-
unmark_created(record)
|
667
|
-
|
668
|
-
attributes = entity_attributes_crud_driver_table.insert(to_persistable(record))
|
669
|
-
record.write_attributes_without_callbacks(attributes)
|
670
|
-
|
671
|
-
# we need to update finding the tracked object by key and removing/reading it seems to be the simplest
|
672
|
-
# way to accomplish that at the moment
|
673
|
-
tracked(record)
|
674
|
-
|
675
|
-
record.is_persisted = record.is_loaded = true
|
676
|
-
record.is_created = false
|
677
|
-
record.save_persisted_attributes
|
678
|
-
end
|
679
|
-
|
680
|
-
def flush_created_associations!(record)
|
681
|
-
entity_class.associations.each_key do |association_data_path|
|
682
|
-
DataPath.values_at(association_data_path, record).each do |associated_record|
|
683
|
-
next unless associated_record.created?
|
684
|
-
|
685
|
-
transaction = Persistence::EntityBase::Transaction.open_transaction_for(associated_record)
|
686
|
-
|
687
|
-
unless transaction
|
688
|
-
# :nocov:
|
689
|
-
raise "No open transaction for #{associated_record}"
|
690
|
-
# :nocov:
|
691
|
-
end
|
692
|
-
|
693
|
-
if transaction.created?(associated_record)
|
694
|
-
transaction.flush_created_record!(associated_record)
|
695
|
-
end
|
696
|
-
end
|
697
|
-
end
|
698
|
-
end
|
699
|
-
|
700
664
|
def flush_updated_and_hard_deleted!
|
701
665
|
# TODO: use bulk operations to improve performance...
|
702
666
|
marked_updated.each do |record|
|
703
|
-
|
704
|
-
record.write_attributes_without_callbacks(attributes)
|
667
|
+
entity_attributes_crud_driver_table.update(to_persistable(record))
|
705
668
|
record.save_persisted_attributes
|
706
669
|
end
|
707
670
|
|
@@ -753,16 +716,14 @@ module Foobara
|
|
753
716
|
|
754
717
|
def normalize_attributes(attributes)
|
755
718
|
if attributes
|
756
|
-
|
757
|
-
attributes = attributes.transform_keys(&:to_sym)
|
719
|
+
attributes = attributes.transform_keys(&:to_sym)
|
758
720
|
|
759
|
-
|
760
|
-
|
721
|
+
primary_key_name = entity_class.primary_key_attribute
|
722
|
+
primary_key_value = attributes[primary_key_name]
|
761
723
|
|
762
|
-
|
724
|
+
attributes[primary_key_name] = entity_class.primary_key_type.cast!(primary_key_value)
|
763
725
|
|
764
|
-
|
765
|
-
end
|
726
|
+
attributes
|
766
727
|
end
|
767
728
|
end
|
768
729
|
end
|
@@ -21,6 +21,45 @@ module Foobara
|
|
21
21
|
end.call
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def order_entity_classes(entity_classes)
|
26
|
+
return entity_classes if entity_classes.size <= 1
|
27
|
+
|
28
|
+
without_associations, with_associations = entity_classes.partition do |entity_class|
|
29
|
+
entity_class.associations.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
if with_associations.size > 1
|
33
|
+
i = 0
|
34
|
+
end_at = with_associations.size - 1
|
35
|
+
|
36
|
+
while i < end_at
|
37
|
+
entity_class = with_associations[i]
|
38
|
+
associations = entity_class.associations.values.uniq
|
39
|
+
|
40
|
+
changed = false
|
41
|
+
|
42
|
+
j = i + 1
|
43
|
+
|
44
|
+
while j <= end_at
|
45
|
+
other = with_associations[j]
|
46
|
+
|
47
|
+
if associations.include?(other.foobara_type)
|
48
|
+
with_associations[j] = entity_class
|
49
|
+
with_associations[i] = other
|
50
|
+
changed = true
|
51
|
+
break
|
52
|
+
end
|
53
|
+
|
54
|
+
j += 1
|
55
|
+
end
|
56
|
+
|
57
|
+
i += 1 unless changed
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
without_associations + with_associations
|
62
|
+
end
|
24
63
|
end
|
25
64
|
|
26
65
|
def initialize(name, entity_attributes_crud_driver:)
|
@@ -99,6 +99,10 @@ module Foobara
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def objects_to_bases(objects)
|
102
|
+
if objects.size > 1 && objects.all? { |o| o.is_a?(::Class) && o < Entity }
|
103
|
+
objects = EntityBase.order_entity_classes(objects)
|
104
|
+
end
|
105
|
+
|
102
106
|
objects.map do |object|
|
103
107
|
object_to_base(object)
|
104
108
|
end.uniq
|
@@ -25,12 +25,16 @@ module Foobara
|
|
25
25
|
TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
26
26
|
)
|
27
27
|
|
28
|
-
|
29
|
-
type:
|
28
|
+
declaration = TypeDeclaration.new(
|
29
|
+
type: :attributes,
|
30
30
|
element_type_declarations:,
|
31
31
|
required:,
|
32
32
|
defaults:
|
33
33
|
)
|
34
|
+
declaration.is_absolutified = true
|
35
|
+
declaration.is_duped = true
|
36
|
+
|
37
|
+
handler.desugarize(declaration).declaration_data
|
34
38
|
end
|
35
39
|
|
36
40
|
def only(declaration, *keys)
|
@@ -49,9 +53,8 @@ module Foobara
|
|
49
53
|
reject(declaration, keys_to_reject)
|
50
54
|
end
|
51
55
|
|
52
|
-
def reject(
|
53
|
-
|
54
|
-
declaration = Util.deep_dup(declaration)
|
56
|
+
def reject(declaration_data, *keys)
|
57
|
+
declaration = TypeDeclaration.new(declaration_data)
|
55
58
|
|
56
59
|
element_type_declarations = declaration[:element_type_declarations]
|
57
60
|
required = declaration[:required]
|
@@ -64,17 +67,20 @@ module Foobara
|
|
64
67
|
|
65
68
|
if element_type_declarations.key?(key)
|
66
69
|
changed = true
|
67
|
-
element_type_declarations.
|
70
|
+
declaration[:element_type_declarations] = declaration[:element_type_declarations].except(key)
|
68
71
|
end
|
69
72
|
|
70
73
|
if required&.include?(key)
|
71
74
|
changed = true
|
75
|
+
required = required.dup
|
72
76
|
required.delete(key)
|
77
|
+
declaration[:required] = required
|
73
78
|
end
|
74
79
|
|
75
80
|
if defaults&.key?(key)
|
76
81
|
changed = true
|
77
|
-
defaults.
|
82
|
+
defaults = defaults.except(key)
|
83
|
+
declaration[:defaults] = defaults
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
@@ -83,9 +89,9 @@ module Foobara
|
|
83
89
|
TypeDeclarations::Handlers::ExtendAttributesTypeDeclaration
|
84
90
|
)
|
85
91
|
|
86
|
-
handler.desugarize(declaration)
|
92
|
+
handler.desugarize(declaration).declaration_data
|
87
93
|
else
|
88
|
-
|
94
|
+
declaration_data
|
89
95
|
end
|
90
96
|
end
|
91
97
|
end
|
@@ -48,7 +48,7 @@ module Foobara
|
|
48
48
|
|
49
49
|
declaration[:element_type_declarations].each_pair do |attribute_name, declaration_data|
|
50
50
|
element_type_declarations[attribute_name] = if from_yaml.include?(attribute_name)
|
51
|
-
|
51
|
+
:string
|
52
52
|
else
|
53
53
|
declaration_data
|
54
54
|
end
|
@@ -117,7 +117,8 @@ module Foobara
|
|
117
117
|
_add_attribute(attribute_name, type)
|
118
118
|
else
|
119
119
|
declaration = if block
|
120
|
-
attributes_declaration =
|
120
|
+
attributes_declaration =
|
121
|
+
Attributes.to_declaration(&block).declaration_data.merge(declaration)
|
121
122
|
|
122
123
|
if type == :array
|
123
124
|
{
|
@@ -173,13 +174,21 @@ module Foobara
|
|
173
174
|
|
174
175
|
def _type_declaration
|
175
176
|
@_type_declaration ||= begin
|
176
|
-
|
177
|
-
type:
|
177
|
+
declaration = TypeDeclaration.new(
|
178
|
+
type: :attributes,
|
178
179
|
element_type_declarations: {}
|
179
|
-
|
180
|
+
)
|
181
|
+
|
182
|
+
declaration.is_absolutified = true
|
183
|
+
declaration.is_duped = true
|
180
184
|
|
181
185
|
handler = Domain.current.foobara_type_builder.handler_for_class(Handlers::ExtendAttributesTypeDeclaration)
|
182
|
-
handler.desugarize(
|
186
|
+
declaration = handler.desugarize(declaration)
|
187
|
+
|
188
|
+
declaration.is_strict = false
|
189
|
+
declaration.is_absolutified = true
|
190
|
+
|
191
|
+
declaration
|
183
192
|
end
|
184
193
|
end
|
185
194
|
end
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/array_desugarizer.rb
CHANGED
@@ -8,18 +8,38 @@ module Foobara
|
|
8
8
|
# TODO: make a quick way to convert a couple simple procs into a transformer
|
9
9
|
class ArrayDesugarizer < TypeDeclarations::Desugarizer
|
10
10
|
def applicable?(sugary_type_declaration)
|
11
|
-
sugary_type_declaration.
|
11
|
+
sugary_type_declaration.array? && sugary_type_declaration.size <= 1 && !sugary_type_declaration.strict?
|
12
12
|
end
|
13
13
|
|
14
14
|
def desugarize(sugary_type_declaration)
|
15
|
-
strict_type_declaration =
|
15
|
+
strict_type_declaration = sugary_type_declaration
|
16
|
+
sugary_type_declaration = sugary_type_declaration.declaration_data
|
17
|
+
|
18
|
+
strict_type_declaration.declaration_data = { type: :array }
|
19
|
+
strict_type_declaration.is_duped = true
|
20
|
+
strict_type_declaration.is_absolutified = true
|
16
21
|
|
17
22
|
unless sugary_type_declaration.empty?
|
18
23
|
element_type_declaration = sugary_type_declaration.first
|
19
24
|
|
20
|
-
|
25
|
+
element_type_declaration = if element_type_declaration.is_a?(Types::Type)
|
26
|
+
element_type_declaration.reference_or_declaration_data
|
27
|
+
else
|
28
|
+
declaration = TypeDeclaration.new(element_type_declaration)
|
29
|
+
|
30
|
+
if strict_type_declaration.deep_duped?
|
31
|
+
# TODO: probably not worth directly testing this path
|
32
|
+
# :nocov:
|
33
|
+
declaration.is_deep_duped = true
|
34
|
+
declaration.is_duped = true
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
|
38
|
+
handler = type_declaration_handler_for(declaration)
|
39
|
+
handler.desugarize(declaration).declaration_data
|
40
|
+
end
|
21
41
|
|
22
|
-
strict_type_declaration[:element_type_declaration] =
|
42
|
+
strict_type_declaration[:element_type_declaration] = element_type_declaration
|
23
43
|
end
|
24
44
|
|
25
45
|
strict_type_declaration
|
@@ -4,23 +4,37 @@ module Foobara
|
|
4
4
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
5
5
|
class ElementTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
return false
|
8
|
-
return false unless
|
9
|
-
|
10
|
-
sugary_type_declaration = Util.symbolize_keys(sugary_type_declaration)
|
11
|
-
|
12
|
-
return false unless sugary_type_declaration.key?(:type)
|
7
|
+
return false if sugary_type_declaration.strict?
|
8
|
+
return false unless sugary_type_declaration.hash?
|
9
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
13
10
|
|
14
11
|
type_symbol = sugary_type_declaration[:type]
|
15
12
|
|
16
|
-
type_symbol == :array &&
|
13
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :array &&
|
14
|
+
sugary_type_declaration.key?(:element_type_declaration)
|
17
15
|
end
|
18
16
|
|
19
17
|
def desugarize(sugary_type_declaration)
|
18
|
+
sugary_type_declaration.symbolize_keys!
|
19
|
+
|
20
20
|
sugar = sugary_type_declaration[:element_type_declaration]
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
strict = if sugar.is_a?(Types::Type)
|
23
|
+
sugar.reference_or_declaration_data
|
24
|
+
else
|
25
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
# TODO: probably not worth directly testing this path
|
29
|
+
# :nocov:
|
30
|
+
declaration.is_deep_duped = true
|
31
|
+
declaration.is_duped = true
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
|
35
|
+
handler = type_declaration_handler_for(declaration)
|
36
|
+
handler.desugarize(declaration).declaration_data
|
37
|
+
end
|
24
38
|
|
25
39
|
sugary_type_declaration[:element_type_declaration] = strict
|
26
40
|
|
data/projects/type_declarations/src/handlers/extend_array_type_declaration/to_type_transformer.rb
CHANGED
@@ -7,13 +7,9 @@ module Foobara
|
|
7
7
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
8
8
|
class ToTypeTransformer < ExtendAssociativeArrayTypeDeclaration::ToTypeTransformer
|
9
9
|
def transform(strict_type_declaration)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if element_type_declaration
|
14
|
-
type.element_type = type_for_declaration(element_type_declaration)
|
15
|
-
end
|
16
|
-
end
|
10
|
+
type = super
|
11
|
+
type.element_type = :Array
|
12
|
+
type
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
@@ -7,21 +7,32 @@ module Foobara
|
|
7
7
|
# TODO: make a quick way to convert a couple simple procs into a transformer
|
8
8
|
class TypeSetToArrayDesugarizer < ArrayDesugarizer
|
9
9
|
def applicable?(sugary_type_declaration)
|
10
|
-
if sugary_type_declaration.
|
11
|
-
extra_keys = sugary_type_declaration.keys -
|
10
|
+
if sugary_type_declaration.hash? && sugary_type_declaration.key?(:type)
|
11
|
+
extra_keys = sugary_type_declaration.declaration_data.keys -
|
12
|
+
[:type, :description, :sensitive, :sensitive_exposed]
|
12
13
|
|
13
14
|
return false if extra_keys.any?
|
14
15
|
|
15
16
|
type = sugary_type_declaration[:type]
|
16
17
|
|
17
18
|
if type.is_a?(::Array)
|
18
|
-
super(type)
|
19
|
+
super(TypeDeclaration.new(type))
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
def desugarize(sugary_type_declaration)
|
24
|
-
strict_type_declaration =
|
25
|
+
strict_type_declaration = TypeDeclaration.new(sugary_type_declaration[:type])
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
# TODO: probably not worth testing this path
|
29
|
+
# :nocov:
|
30
|
+
strict_type_declaration.is_deep_duped = true
|
31
|
+
strict_type_declaration.is_duped = true
|
32
|
+
# :nocov:
|
33
|
+
end
|
34
|
+
|
35
|
+
strict_type_declaration = super(strict_type_declaration)
|
25
36
|
|
26
37
|
if sugary_type_declaration.key?(:description)
|
27
38
|
strict_type_declaration[:description] = sugary_type_declaration[:description]
|
@@ -4,9 +4,19 @@ module Foobara
|
|
4
4
|
# Hmmmm... this inheritance feels backwards
|
5
5
|
class ExtendArrayTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
6
6
|
def applicable?(sugary_type_declaration)
|
7
|
-
strictish_type_declaration =
|
7
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
8
|
+
sugary_type_declaration
|
9
|
+
else
|
10
|
+
desugarize(sugary_type_declaration.clone)
|
11
|
+
end
|
8
12
|
|
9
|
-
strictish_type_declaration.
|
13
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :array
|
14
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
15
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
16
|
+
end
|
17
|
+
|
18
|
+
true
|
19
|
+
end
|
10
20
|
end
|
11
21
|
end
|
12
22
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Foobara
|
2
|
+
module TypeDeclarations
|
3
|
+
module Handlers
|
4
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
5
|
+
class KeyTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
6
|
+
def applicable?(sugary_type_declaration)
|
7
|
+
return false if sugary_type_declaration.strict?
|
8
|
+
return false unless sugary_type_declaration.hash?
|
9
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
10
|
+
|
11
|
+
type_symbol = sugary_type_declaration[:type]
|
12
|
+
|
13
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :associative_array &&
|
14
|
+
sugary_type_declaration.key?(:key_type_declaration)
|
15
|
+
end
|
16
|
+
|
17
|
+
def desugarize(sugary_type_declaration)
|
18
|
+
sugary_type_declaration.symbolize_keys!
|
19
|
+
|
20
|
+
sugar = sugary_type_declaration[:key_type_declaration]
|
21
|
+
|
22
|
+
strict = if sugar.is_a?(Types::Type)
|
23
|
+
sugar.reference_or_declaration_data
|
24
|
+
else
|
25
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
26
|
+
|
27
|
+
if sugary_type_declaration.deep_duped?
|
28
|
+
declaration.is_deep_duped = true
|
29
|
+
declaration.is_duped = true
|
30
|
+
end
|
31
|
+
|
32
|
+
handler = type_declaration_handler_for(declaration)
|
33
|
+
handler.desugarize(declaration).declaration_data
|
34
|
+
end
|
35
|
+
|
36
|
+
sugary_type_declaration[:key_type_declaration] = strict
|
37
|
+
|
38
|
+
sugary_type_declaration
|
39
|
+
end
|
40
|
+
|
41
|
+
def priority
|
42
|
+
Priority::LOW
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -9,17 +9,9 @@ module Foobara
|
|
9
9
|
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
10
10
|
class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
|
11
11
|
def transform(strict_type_declaration)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
if key_type_declaration || value_type_declaration
|
17
|
-
type.element_types = [
|
18
|
-
type_for_declaration(key_type_declaration || :duck),
|
19
|
-
type_for_declaration(value_type_declaration || :duck)
|
20
|
-
]
|
21
|
-
end
|
22
|
-
end
|
12
|
+
type = super
|
13
|
+
type.element_types = :Hash
|
14
|
+
type
|
23
15
|
end
|
24
16
|
end
|
25
17
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative "../extend_registered_type_declaration"
|
2
|
+
require_relative "../../desugarizer"
|
3
|
+
|
4
|
+
module Foobara
|
5
|
+
module TypeDeclarations
|
6
|
+
module Handlers
|
7
|
+
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
8
|
+
class ValueTypeDeclarationDesugarizer < TypeDeclarations::Desugarizer
|
9
|
+
def applicable?(sugary_type_declaration)
|
10
|
+
return false if sugary_type_declaration.strict?
|
11
|
+
return false unless sugary_type_declaration.hash?
|
12
|
+
return false unless sugary_type_declaration.all_symbolizable_keys?
|
13
|
+
|
14
|
+
type_symbol = sugary_type_declaration[:type]
|
15
|
+
|
16
|
+
type_symbol.is_a?(::Symbol) && type_symbol == :associative_array &&
|
17
|
+
sugary_type_declaration.key?(:value_type_declaration)
|
18
|
+
end
|
19
|
+
|
20
|
+
def desugarize(sugary_type_declaration)
|
21
|
+
sugary_type_declaration.symbolize_keys!
|
22
|
+
|
23
|
+
sugar = sugary_type_declaration[:value_type_declaration]
|
24
|
+
|
25
|
+
strict = if sugar.is_a?(Types::Type)
|
26
|
+
sugar.reference_or_declaration_data
|
27
|
+
else
|
28
|
+
declaration = sugary_type_declaration.clone_from_part(sugar)
|
29
|
+
|
30
|
+
if sugary_type_declaration.deep_duped?
|
31
|
+
declaration.is_deep_duped = true
|
32
|
+
declaration.is_duped = true
|
33
|
+
end
|
34
|
+
|
35
|
+
handler = type_declaration_handler_for(declaration)
|
36
|
+
handler.desugarize(declaration).declaration_data
|
37
|
+
end
|
38
|
+
|
39
|
+
sugary_type_declaration[:value_type_declaration] = strict
|
40
|
+
|
41
|
+
sugary_type_declaration
|
42
|
+
end
|
43
|
+
|
44
|
+
def priority
|
45
|
+
Priority::LOW
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -5,9 +5,19 @@ module Foobara
|
|
5
5
|
module Handlers
|
6
6
|
class ExtendAssociativeArrayTypeDeclaration < ExtendRegisteredTypeDeclaration
|
7
7
|
def applicable?(sugary_type_declaration)
|
8
|
-
strictish_type_declaration =
|
8
|
+
strictish_type_declaration = if sugary_type_declaration.strict?
|
9
|
+
sugary_type_declaration
|
10
|
+
else
|
11
|
+
desugarize(sugary_type_declaration.clone)
|
12
|
+
end
|
9
13
|
|
10
|
-
strictish_type_declaration.
|
14
|
+
if strictish_type_declaration.hash? && strictish_type_declaration[:type] == :associative_array
|
15
|
+
unless strictish_type_declaration.equal?(sugary_type_declaration)
|
16
|
+
sugary_type_declaration.assign(strictish_type_declaration)
|
17
|
+
end
|
18
|
+
|
19
|
+
true
|
20
|
+
end
|
11
21
|
end
|
12
22
|
|
13
23
|
# TODO: do we really need this? Isn't this the default?
|
data/projects/type_declarations/src/handlers/extend_attributes_type_declaration/dsl_desugarizer.rb
CHANGED
@@ -6,7 +6,7 @@ module Foobara
|
|
6
6
|
class ExtendAttributesTypeDeclaration < ExtendAssociativeArrayTypeDeclaration
|
7
7
|
class DslDesugarizer < TypeDeclarations::Desugarizer
|
8
8
|
def applicable?(sugary_type_declaration)
|
9
|
-
sugary_type_declaration.
|
9
|
+
sugary_type_declaration.proc?
|
10
10
|
end
|
11
11
|
|
12
12
|
def desugarize(block)
|