Sha256: cddd949eb8c14e92932665a9c66d964d45b5f7ddaa3eff5c2c261e33706edf7a

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Pragma
  module Decorator
    module Association
      module Adapter
        # This is the fallback adapter that is used when no other adpater is compatible with a
        # model. It simply calls +#id+ on the associated object to get the PK and returns the
        # associated object itself when expanding.
        #
        # @api private
        class Poro < Base
          class << self
            # Returns whether the adapter supports the model.
            #
            # Since this is the default adapter, this always returns +true+.
            #
            # @param _model [Object] the model to check
            #
            # @return [Boolean] always +true+
            def supports?(_model)
              true
            end
          end

          # Returns the PK of the associated object.
          #
          # This adapter simply calls +#id+ on the associated object or returns +nil+ if there is
          # no associated object.
          #
          # @return [Integer|String|NilClass] the PK of the associated object
          def primary_key
            associated_object&.id
          end

          # Returns the expanded associated object.
          #
          # This adapter simply returns the associated object itself.
          #
          # @return [Object] the associated object
          def full_object
            associated_object
          end
        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/poro.rb
pragma-decorator-2.1.1 lib/pragma/decorator/association/adapter/poro.rb
pragma-decorator-2.1.0 lib/pragma/decorator/association/adapter/poro.rb