Sha256: f2c88e26048d65dec5e6ab9ed03ed9dcc1b93bf827bf4523d6a4ed3247c582d7

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    class Adaptor
      include Fingerprintable::Mixin
      include SimplySerializable::Mixin
      include Validatable

      serialize only: %i[
        adaptor_configuration
      ]

      def initialize(*)
        raise NotImplementedError
      end

      def adaptor_configuration
        self.class.config
      end

      def base_module
        adaptor_configuration.base_module
      end

      def ledger_attributes_to_save
        return {} if self.class.ledger_attributes_to_save.nil?

        Hash[self.class.ledger_attributes_to_save.map do |attribute|
          [attribute, send(attribute)]
        end]
      end

      def searcher_for?(resource_type:)
        searcher_klass_for(resource_type: resource_type)
      rescue NameError
        false
      end

      def searcher_klass_for(resource_type:)
        base_module.const_get(LedgerSync::Util::StringHelpers.camelcase(resource_type.to_s))::Searcher
      end

      def url_for(*_args)
        raise NotImplementedError
      end

      def parse_operation_error(*)
        nil
      end

      def self.config
        @config ||= LedgerSync.adaptors.config_from_klass(klass: self)
      end

      # These are attributes that must always be saved after the adaptor is called.
      # For example, the library will handle refreshing tokens that will need
      # to be saved back to the application layer for future use.
      def self.ledger_attributes_to_save
        raise NotImplementedError
      end

      def self.url_for(resource: nil); end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-1.1.3 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.1.2 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.1.1 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.0.10 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/adaptor.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/adaptor.rb