Class: Foobara::TypeDeclarations::Handlers::ExtendModelTypeDeclaration::ModelClassDesugarizer
- Inherits:
-
Desugarizer
- Object
- Value::Processor
- Value::Transformer
- Desugarizer
- Foobara::TypeDeclarations::Handlers::ExtendModelTypeDeclaration::ModelClassDesugarizer
- Defined in:
- foobara-0.0.110/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb
Direct Known Subclasses
Foobara::TypeDeclarations::Handlers::ExtendDetachedEntityTypeDeclaration::ModelClassDesugarizer
Instance Attribute Summary
Attributes inherited from Value::Processor
#created_in_namespace, #declaration_data, #parent_declaration_data
Instance Method Summary collapse
- #applicable?(sugary_type_declaration) ⇒ Boolean
- #default_model_base_class ⇒ Object
-
#desugarize(strictish_type_declaration) ⇒ Object
TODO: consider splitting this up into multiple desugarizers.
- #expected_type_symbol ⇒ Object
- #priority ⇒ Object
Methods inherited from Desugarizer
foobara_manifest, requires_declaration_data?, #transform
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods inherited from Value::Transformer
create, error_classes, foobara_manifest, #process_value, subclass, #transform
Methods inherited from Value::Processor
#always_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, #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
Constructor Details
This class inherits a constructor from Foobara::Value::Processor
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Foobara::Value::Processor
Instance Method Details
#applicable?(sugary_type_declaration) ⇒ Boolean
6 7 8 |
# File 'foobara-0.0.110/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb', line 6 def applicable?(sugary_type_declaration) sugary_type_declaration[:type] == expected_type_symbol end |
#default_model_base_class ⇒ Object
14 15 16 |
# File 'foobara-0.0.110/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb', line 14 def default_model_base_class Foobara::Model end |
#desugarize(strictish_type_declaration) ⇒ Object
TODO: consider splitting this up into multiple desugarizers
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 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'foobara-0.0.110/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb', line 19 def desugarize(strictish_type_declaration) if strictish_type_declaration.key?(:model_module) model_module = strictish_type_declaration[:model_module] strictish_type_declaration[:model_module] = case model_module when ::Module model_module.name when ::String, nil model_module else # :nocov: raise ArgumentError, "expected #{model_module} to be a module or module name" # :nocov: end end if strictish_type_declaration.key?(:model_class) klass = strictish_type_declaration[:model_class] model_class_name = if klass && Object.const_defined?(klass) && Object.const_get(klass).is_a?(::Class) model_class = Object.const_get(klass) unless strictish_type_declaration[:model_module] model_module = Util.module_for(model_class) unless model_module == Object strictish_type_declaration[:model_module] = model_module&.name end end strictish_type_declaration[:model_base_class] = model_class.superclass.name model_class.name elsif klass.is_a?(::String) klass else # :nocov: raise ArgumentError, "expected #{klass} to be a class or class name" # :nocov: end strictish_type_declaration[:model_class] = model_class_name end model_base_class = strictish_type_declaration[:model_base_class] || default_model_base_class strictish_type_declaration[:model_base_class] = case model_base_class when ::Class model_base_class.name || model_base_class.model_name when ::String model_base_class else # :nocov: raise ArgumentError, "expected #{model_base_class} to be a class or class name" # :nocov: end if strictish_type_declaration[:name].is_a?(::Symbol) strictish_type_declaration[:name] = strictish_type_declaration[:name].to_s end if strictish_type_declaration[:model_module].nil? strictish_type_declaration.delete(:model_module) end strictish_type_declaration[:model_class] ||= [ *strictish_type_declaration[:model_module], strictish_type_declaration[:name] ].join("::") strictish_type_declaration end |
#expected_type_symbol ⇒ Object
10 11 12 |
# File 'foobara-0.0.110/projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/model_class_desugarizer.rb', line 10 def expected_type_symbol :model end |