Class: Trifle::Logs::Operations::Searcher

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/logs/operations/searcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**keywords) ⇒ Searcher

Returns a new instance of Searcher.



9
10
11
12
13
14
15
# File 'lib/trifle/logs/operations/searcher.rb', line 9

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

Instance Attribute Details

#max_locObject (readonly)

Returns the value of attribute max_loc.



7
8
9
# File 'lib/trifle/logs/operations/searcher.rb', line 7

def max_loc
  @max_loc
end

#min_locObject (readonly)

Returns the value of attribute min_loc.



7
8
9
# File 'lib/trifle/logs/operations/searcher.rb', line 7

def min_loc
  @min_loc
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/trifle/logs/operations/searcher.rb', line 7

def namespace
  @namespace
end

#patternObject (readonly)

Returns the value of attribute pattern.



7
8
9
# File 'lib/trifle/logs/operations/searcher.rb', line 7

def pattern
  @pattern
end

Instance Method Details

#configObject



17
18
19
# File 'lib/trifle/logs/operations/searcher.rb', line 17

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

#nextObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trifle/logs/operations/searcher.rb', line 42

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

#performObject



21
22
23
24
25
26
27
28
# File 'lib/trifle/logs/operations/searcher.rb', line 21

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

#prevObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trifle/logs/operations/searcher.rb', line 30

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