Sha256: 2618b6991c4d6427f97515ee691c660628e343405fc8558305fb66980d364c9d

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module LedgerSync
  class AdaptorConfiguration
    include Fingerprintable::Mixin
    include SimplySerializable::Mixin

    attr_accessor :module_string,
                  :name,
                  :rate_limiting_wait_in_seconds,
                  :test

    attr_reader :aliases,
                :root_key

    serialize only: %i[
      aliases
      module_string
      root_key
      rate_limiting_wait_in_seconds
      test
    ]

    def initialize(root_key, module_string: nil)
      @root_key = root_key
      @aliases = []
      @module_string = module_string || LedgerSync::Util::StringHelpers.camelcase(root_key)
    end

    def adaptor_klass
      @adaptor_klass ||= base_module::Adaptor
    end

    def add_alias(new_alias)
      @aliases << new_alias
      LedgerSync.adaptors.add_alias(new_alias, self)
    end

    def base_module
      @base_module ||= begin
        LedgerSync::Adaptors.const_get(@module_string)
      end
    end

    # Delegate #new to the adaptor class enabling faster adaptor initialization
    # e.g. LedgerSync.adaptors.test.new(...)
    def new(*args)
      adaptor_klass.new(*args)
    end

    # Delegate #new_from_env to the adaptor class enabling faster adaptor initialization
    # e.g. LedgerSync.adaptors.test.new_from_env(...)
    def new_from_env(*args)
      adaptor_klass.new_from_env(*args)
    end

    def test?
      test == true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.3.4 lib/ledger_sync/adaptor_configuration.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptor_configuration.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptor_configuration.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptor_configuration.rb