Sha256: 782dc66c301dbbdbadd8ebf9f35a3dc0e4e1672dbebabffd5817a591513f5ff1

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

module LedgerSync
  module Adaptors
    class Searcher
      include SimplySerializable::Mixin

      attr_reader :adaptor,
                  :query,
                  :pagination,
                  :resources

      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

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.0.10 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.0.9 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.0.3 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/searcher.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/searcher.rb