Sha256: 5391273f78ec587b0ef431bceac887bb1686bb4988f04eb9765238425341e9a5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 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
          include Adaptor

          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

1 entries across 1 versions & 1 rubygems

Version Path
pragma-decorator-2.2.1 lib/pragma/decorator/association/adapter/poro.rb