Class: Foobara::CommandConnectors::Transformers::EntityToPrimaryKeyInputsTransformer
- Inherits:
-
TypeDeclarations::TypedTransformer
- Object
- Value::Processor
- Value::Transformer
- TypeDeclarations::TypedTransformer
- Foobara::CommandConnectors::Transformers::EntityToPrimaryKeyInputsTransformer
- Defined in:
- foobara-0.0.141/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_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 TypeDeclarations::TypedTransformer
#always_applicable?, from, #from, #from_type, #has_from_type?, #has_to_type?, #initialize, #process_value, requires_declaration_data?, requires_parent_declaration_data?, to, #to, #to_type, #to_type_declaration
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 Foobara::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
#from_type_declaration ⇒ Object
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 80 |
# File 'foobara-0.0.141/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb', line 5 def from_type_declaration return nil unless to_type if contains_associations_or_is_entity?(to_type) if to_type.extends?(Foobara::BuiltinTypes[:attributes]) to_fix = {} to_type.element_types.each_pair do |attribute_name, attribute_type| if contains_associations_or_is_entity?(attribute_type) to_fix[attribute_name] = attribute_type end end element_type_declarations = to_type.declaration_data[:element_type_declarations].dup to_fix.each_pair do |attribute_name, attribute_type| transformer = EntityToPrimaryKeyInputsTransformer.new(to: attribute_type) element_type_declarations[attribute_name] = transformer.from_type_declaration end to_type.declaration_data.merge(element_type_declarations:) elsif to_type.extends?(Foobara::BuiltinTypes[:tuple]) indexes_to_fix = [] to_type.element_types.each.with_index do |element_type, index| if contains_associations_or_is_entity?(element_type) indexes_to_fix << index end end element_type_declarations = to_type.declaration_data[:element_type_declarations].dup indexes_to_fix.each do |index| transformer = EntityToPrimaryKeyInputsTransformer.new(to: to_type.element_types[index]) element_type_declarations[index] = transformer.from_type_declaration end to_type.declaration_data.merge(element_type_declarations:) elsif to_type.extends?(Foobara::BuiltinTypes[:array]) transformer = EntityToPrimaryKeyInputsTransformer.new(to: to_type.element_type) element_type_declaration = transformer.from_type_declaration to_type.declaration_data.merge(element_type_declaration:) elsif to_type.extends?(Foobara::BuiltinTypes[:detached_entity]) declaration = to_type.target_class.primary_key_type.reference_or_declaration_data description = "#{to_type.target_class.model_name} #{to_type.target_class.primary_key_attribute}" unless to_type.extends_directly?(Foobara::BuiltinTypes[:detached_entity]) || to_type.extends_directly?(Foobara::BuiltinTypes[:entity]) description = [ description, *to_type.description ].join(" : ") end declaration[:description] = description if to_type.declaration_data.key?(:allow_nil) declaration[:allow_nil] = to_type.declaration_data[:allow_nil] end declaration elsif to_type.extends?(Foobara::BuiltinTypes[:model]) attributes_type = to_type.target_class.attributes_type EntityToPrimaryKeyInputsTransformer.new(to: attributes_type).from_type_declaration else # :nocov: raise "Not sure how to handle #{to_type}" # :nocov: end else to_type end end |
#transform(inputs) ⇒ Object
82 83 84 |
# File 'foobara-0.0.141/projects/command_connectors/src/transformers/entity_to_primary_key_inputs_transformer.rb', line 82 def transform(inputs) inputs end |