Sha256: 410906aa83064b4ccd3f5d5958b3659f8507dc653684723c26c4ae99b5867fdc

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Ledgers
    module Mixins
      module SerializationMixin
        module ClassMethods
          def inferred_deserializer_class
            @inferred_deserializer_class ||= inferred_serialization_class(type: 'Deserializer')
          end

          def inferred_serialization_class(args = {})
            type = args.fetch(:type)

            inferred_client_class.base_module.const_get(
              "#{inferred_resource_class.resource_module_str}::#{type.camelcase}"
            )
          end

          def inferred_serializer_class
            @inferred_serializer_class ||= inferred_serialization_class(type: 'Serializer')
          end
        end

        def self.included(base)
          base.include InferClientMixin
          base.include InferResourceClassMixin
          base.extend ClassMethods
        end

        def deserializer
          self.class.inferred_deserializer_class.new
        end

        def serializer
          self.class.inferred_serializer_class.new
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.4.4 lib/ledger_sync/ledgers/mixins/serialization_mixin.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/mixins/serialization_mixin.rb
ledger_sync-1.4.1 lib/ledger_sync/ledgers/mixins/serialization_mixin.rb
ledger_sync-1.4.0 lib/ledger_sync/ledgers/mixins/serialization_mixin.rb