Sha256: 66ca7c9eaf52c4f51cf3dfe704739143a32201964b15e18fc69cfc9d0c18a150

Contents?: true

Size: 1.4 KB

Versions: 22

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Ledgers
    class Searcher
      include SimplySerializable::Mixin
      include Mixins::InferResourceClassMixin
      include Mixins::InferSerializerMixin
      include Mixins::SerializationMixin

      attr_reader :client,
                  :query,
                  :pagination,
                  :request

      simply_serialize only: %i[
        client
        query
        pagination
        resources
      ]

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

      def deserializer_class
        @deserializer_class ||= self.class.inferred_deserializer_class
      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(
          client: client,
          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

22 entries across 22 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.5.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.4.4 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.3.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.2.3 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.2.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.2.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.0.2 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.0.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.0.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.8.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.8.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.7.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.6.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.4.4 lib/ledger_sync/ledgers/searcher.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/searcher.rb