Sha256: 37cbb207875d66f4f1b1d5e65fc23e84e6830221d0e394df351956f4b0bb57a3

Contents?: true

Size: 956 Bytes

Versions: 8

Compression:

Stored size: 956 Bytes

Contents

module Foobara
  module BuiltinTypes
    module DetachedEntity
      module Casters
        class Hash < Attributes::Casters::Hash
          class << self
            def requires_parent_declaration_data?
              true
            end
          end

          def cast(attributes)
            symbolized_attributes = super

            entity_class.send(build_method(symbolized_attributes), symbolized_attributes)
          end

          def build_method(_symbolized_attributes)
            :new
          end

          def entity_class
            type = parent_declaration_data[:type]

            if type == expected_type_symbol
              Object.const_get(parent_declaration_data[:model_class])
            else
              Foobara::Namespace.current.foobara_lookup_type!(type).target_class
            end
          end

          def expected_type_symbol
            :detached_entity
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foobara-0.0.38 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.37 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.36 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.35 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.34 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.33 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.32 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb
foobara-0.0.31 projects/detached_entity/src/extensions/builtin_types/detached_entity/casters/hash.rb