Sha256: 989cb26bf1c0a789f6ba9294fe061bfa5bb60d98861836bc12ad41d91b19a4c8

Contents?: true

Size: 1.55 KB

Versions: 8

Compression:

Stored size: 1.55 KB

Contents

module Foobara
  module TypeDeclarations
    module Handlers
      class ExtendEntityTypeDeclaration < ExtendDetachedEntityTypeDeclaration
        class ToTypeTransformer < ExtendDetachedEntityTypeDeclaration::ToTypeTransformer
          # TODO: move this to a more appropriate place
          class EntityPrimaryKeyCaster < Value::Caster
            class << self
              def requires_declaration_data?
                true
              end
            end

            def entity_class
              declaration_data
            end

            def primary_key_type
              entity_class.primary_key_type
            end

            def applicable?(value)
              primary_key_type.applicable?(value)
            end

            def transform(primary_key)
              entity_class.thunk(primary_key)
            end

            def applies_message
              primary_key_type.value_caster.applies_message
            end
          end

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

                unless entity_class.can_be_created_through_casting?
                  type.casters = type.casters.reject do |caster|
                    caster.is_a?(Foobara::BuiltinTypes::Entity::Casters::Hash)
                  end
                end

                type.casters << EntityPrimaryKeyCaster.new(entity_class)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foobara-0.0.38 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.37 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.36 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.35 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.34 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.33 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.32 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb
foobara-0.0.31 projects/entity/src/extensions/type_declarations/handlers/extend_entity_type_declaration/to_type_transformer.rb