Sha256: 378fb4513f67607a9842dea6b23c0fe392948822bb44fc64f5094884d8238991

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Trifle
  module Logs
    module Operations
      class Searcher
        attr_reader :namespace, :pattern, :min_loc, :max_loc

        def initialize(**keywords)
          @namespace = keywords.fetch(:namespace)
          @pattern = keywords.fetch(:pattern)
          @config = keywords[:config]
          @min_loc = keywords[:min_loc]
          @max_loc = keywords[:max_loc]
        end

        def config
          @config || Trifle::Logs.default
        end

        def perform
          result = config.driver.search(
            namespace: namespace, pattern: pattern
          )
          @min_loc = result.min_loc
          @max_loc = result.max_loc
          result
        end

        def prev
          return Trifle::Logs::Result.new if @min_loc.nil?

          result = config.driver.search(
            namespace: namespace, pattern: pattern,
            file_loc: @min_loc, direction: :prev
          )

          @min_loc = result.min_loc
          result
        end

        def next
          return Trifle::Logs::Result.new if @max_loc.nil?

          result = config.driver.search(
            namespace: namespace, pattern: pattern,
            file_loc: @max_loc, direction: :next
          )

          @max_loc = result.max_loc
          result
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trifle-logs-0.2.1 lib/trifle/logs/operations/searcher.rb
trifle-logs-0.2.0 lib/trifle/logs/operations/searcher.rb
trifle-logs-0.1.0 lib/trifle/logs/operations/searcher.rb