Sha256: ea50c3e4e16631161a40257b276bc9af16166f1f2423a7ccd09edd2c56a12467

Contents?: true

Size: 926 Bytes

Versions: 15

Compression:

Stored size: 926 Bytes

Contents

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

          def cast(attributes)
            symbolized_attributes = super

            outcome = entity_class.attributes_type.process_value(symbolized_attributes)

            if outcome.success?
              entity_class.create(symbolized_attributes)
            else
              # we build an instance so that it can fail a validator later. But we already know we don't want to
              # persist this thing. So use build instead of create.
              entity_class.build(outcome.result)
            end
          end

          def entity_class
            Object.const_get(parent_declaration_data[:model_class])
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
foobara-0.0.15 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.14 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.13 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.12 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.11 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.10 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.9 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.8 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.7 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.6 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.5 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.4 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.3 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.2 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb
foobara-0.0.1 projects/entity/src/extensions/builtin_types/entity/casters/hash.rb