Sha256: e7e02c0547d9bf232a12fd77b4fb27611dc3e45105fe0a6a9632edd2a32b5d33

Contents?: true

Size: 1.99 KB

Versions: 9

Compression:

Stored size: 1.99 KB

Contents

module Foobara
  module TypeDeclarations
    module Handlers
      class ExtendModelTypeDeclaration < ExtendRegisteredTypeDeclaration
        class ToTypeTransformer < ExtendRegisteredTypeDeclaration::ToTypeTransformer
          # TODO: make declaration validator for model_class and model_base_class
          def target_classes(strict_type_declaration)
            Object.const_get(strict_type_declaration[:model_class])
          end

          # TODO: must explode if name missing...
          def type_name(strict_type_declaration)
            strict_type_declaration[:name]
          end

          # TODO: create declaration validator for name and the others
          # TODO: seems like a smell that we don't have processors for these?
          def non_processor_keys
            [:name, :model_class, :model_base_class, :model_module, :attributes_declaration, *super]
          end

          def process_value(...)
            super.tap do |outcome|
              if outcome.success?
                type = outcome.result

                handler = handler_for_class(ExtendAttributesTypeDeclaration)
                attributes_type_declaration = type.declaration_data[:attributes_declaration]

                type.element_types = handler.process_value!(attributes_type_declaration)

                model_class = type.target_class
                existing_model_type = model_class.model_type

                domain = model_class.domain || Domain.global

                if existing_model_type
                  # :nocov:
                  raise "Did not expect #{type.declaration_data[:name]} to already exist"
                  # :nocov:
                else
                  model_class.model_type = type
                  type.type_symbol = type.declaration_data[:name]
                  model_class.description type.declaration_data[:description]
                  domain.foobara_register_model(model_class)
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
foobara-0.0.47 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.46 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.45 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.44 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.43 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.42 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.41 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.40 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb
foobara-0.0.39 projects/model/src/extensions/type_declarations/handlers/extend_model_type_declaration/to_type_transformer.rb