Sha256: 01527fe2bdbb8788dce74a701f3544abea8648478bd3394d26dee2786303cc7d

Contents?: true

Size: 905 Bytes

Versions: 18

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Serialization
    module Type
      class DeserializerType < LedgerSync::Type::Value
        attr_reader :deserializer

        def initialize(args = {})
          @deserializer = args.fetch(:deserializer)

          super()
        end

        def cast_value(args = {})
          deserializer_attribute = args.fetch(:deserializer_attribute)
          resource               = args.fetch(:resource)
          value                  = args.fetch(:value)

          first_dot = deserializer_attribute.resource_attribute_dot_parts.first.to_sym
          nested_resource = resource.send(first_dot)
          nested_resource ||= resource.class.resource_attributes[first_dot].type.resource_class.new

          return if value.nil?

          deserializer.new.deserialize(hash: value, resource: nested_resource)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.5.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.4.4 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.3.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.2.3 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.2.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.2.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.0.2 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.0.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.0.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.8.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.8.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.7.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.6.0 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.5.2 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.5.1 lib/ledger_sync/serialization/type/deserializer_type.rb
ledger_sync-1.5.0 lib/ledger_sync/serialization/type/deserializer_type.rb