Class: Foobara::CommandConnectors::ShCliConnector::ModelsToAttributesInputsTransformer

Inherits:
TypeDeclarations::TypedTransformer show all
Defined in:
foobara-sh-cli-connector-0.0.17/src/models_to_attributes_inputs_transformer.rb

Instance Attribute Summary

Attributes inherited from Value::Processor

#created_in_namespace, #declaration_data, #parent_declaration_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TypeDeclarations::TypedTransformer

from, #from, #from_type, #from_type_declaration, #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

Class Method Details

.type_declaration(from_type) ⇒ Object

[View source]

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
# File 'foobara-sh-cli-connector-0.0.17/src/models_to_attributes_inputs_transformer.rb', line 10

def type_declaration(from_type)
  if from_type.extends?(BuiltinTypes[:entity])
    from_type.target_class.primary_key_type
  elsif from_type.extends?(BuiltinTypes[:model])
    from_type.target_class.attributes_type
  elsif from_type.extends?(BuiltinTypes[:tuple])
    # TODO: implement this logic for tuple
    raise "Tuple not yet supported"
  elsif from_type.extends?(BuiltinTypes[:array])
    element_type = from_type.element_type

    if element_type
      declaration_data = Util.deep_dup(from_type.declaration_data)

      declaration_data[:element_type_declaration] = type_declaration(element_type)

      declaration_data
    else
      from_type
    end
  elsif from_type.extends?(BuiltinTypes[:attributes])
    declaration_data = Util.deep_dup(from_type.declaration_data)

    declaration_data[:element_type_declarations] = from_type.element_types.transform_values do |t|
      type_declaration(t)
    end

    declaration_data
  elsif from_type.extends?(BuiltinTypes[:associative_array])
    # TODO: implement this
    raise "Associative array not yet supported"
  else
    from_type
  end
end

Instance Method Details

#transform(inputs) ⇒ Object

Since attributes are castable to models, we can just use an identity function here

[View source]

48
49
50
# File 'foobara-sh-cli-connector-0.0.17/src/models_to_attributes_inputs_transformer.rb', line 48

def transform(inputs)
  inputs
end