Sha256: 4eea19ddf863b98b0814fa9c69d615cfb89ebd7a6bcfb47e366c760555af0c51
Contents?: true
Size: 1.77 KB
Versions: 26
Compression:
Stored size: 1.77 KB
Contents
module Foobara module TypeDeclarations module Handlers class ExtendEntityTypeDeclaration < ExtendModelTypeDeclaration class ToTypeTransformer < ExtendModelTypeDeclaration::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 non_processor_keys [:primary_key, *super] 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.primary_key_attribute entity_class.primary_key(strict_declaration_type[:primary_key]) end 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
26 entries across 26 versions & 1 rubygems