Sha256: e949fa8b4466e7526ae4de2456d1abfd6913b3810451714a4ec22d28842af251

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true

module Pragma
  module Decorator
    module Association
      # Adapters make associations ORM-independent by providing support for multiple underlying
      # libraries like ActiveRecord and simple POROs.
      #
      # @api private
      module Adapter
        # The list of supported adapters, in order of priority.
        SUPPORTED_ADAPTERS = [ActiveRecord, Poro].freeze

        # Loads the adapter for the given association bond.
        #
        # This will try {SUPPORTED_ADAPTERS} in order until it finds an adapter that supports the
        # bond's model. When the adapter is found, it will return a new instance of it.
        #
        # @param bond [Bond] the bond to load the adapter for
        #
        # @return [Adapter::Base]
        #
        # @see Adapter::Base.supports?
        def self.load_for(bond)
          SUPPORTED_ADAPTERS.find do |adapter|
            adapter.supports?(bond.model)
          end.new(bond)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pragma-decorator-2.2.0 lib/pragma/decorator/association/adapter.rb
pragma-decorator-2.1.1 lib/pragma/decorator/association/adapter.rb
pragma-decorator-2.1.0 lib/pragma/decorator/association/adapter.rb