Sha256: b912fd72f8bf6dc470bf9fa15be43b9d37e50d260ede28eb29feb1156e3d3d27

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    class Searcher
      include SimplySerializable::Mixin
      include Mixins::InferResourceClassMixin
      include Mixins::InferLedgerSerializerMixin

      attr_reader :adaptor,
                  :query,
                  :pagination,
                  :request

      serialize only: %i[
        adaptor
        query
        pagination
        resources
      ]

      def initialize(adaptor:, query:, pagination: {})
        @adaptor = adaptor
        @query = query
        @pagination = pagination
      end

      def next_searcher
        raise NotImplementedError
      end

      def previous_searcher
        raise NotImplementedError
      end

      def resources
        raise NotImplementedError
      end

      def search
        @search ||= success
      end

      private

      def paginate(**keywords)
        self.class.new(
          adaptor: adaptor,
          query: query,
          pagination: keywords
        )
      end

      def success
        SearchResult.Success(
          searcher: self
        )
      end

      def failure(searcher: nil, **keywords)
        SearchResult.Failure(
          searcher: searcher || self,
          **keywords
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.3.3 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/searcher.rb