Sha256: c148c43a58bc4ee50b8130209646bc36a798e2b93cea1380e3a64e7620dafd72

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

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

    attr_accessor :module,
                  :name,
                  :rate_limiting_wait_in_seconds,
                  :test

    attr_reader :aliases,
                :root_key

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

    def initialize(root_key)
      @root_key = root_key
      @aliases = []
      @module = LedgerSync::Util::StringHelpers.camelcase(root_key)
    end

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

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

    def add_alias(new_alias)
      @aliases << new_alias
      LedgerSync.adaptors.add_alias(new_alias, self)
    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

    def test?
      test == true
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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