Class: Factbase::Impatient::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/impatient.rb

Overview

Query decorator.

This is an internal class, it is not supposed to be instantiated directly.

Instance Method Summary collapse

Constructor Details

#initialize(term, maps, timeout, fb) ⇒ Query

Returns a new instance of Query.



47
48
49
50
51
52
# File 'lib/factbase/impatient.rb', line 47

def initialize(term, maps, timeout, fb)
  @term = term
  @maps = maps
  @timeout = timeout
  @fb = fb
end

Instance Method Details

#delete!(fb = @fb) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/factbase/impatient.rb', line 77

def delete!(fb = @fb)
  qry = @fb.query(@term, @maps)
  Timeout.timeout(@timeout) do
    qry.delete!(fb)
  end
rescue Timeout::Error => e
  raise "delete!() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
end

#each(fb = @fb, params = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/factbase/impatient.rb', line 58

def each(fb = @fb, params = {}, &)
  return to_enum(__method__, fb, params) unless block_given?
  qry = @fb.query(@term, @maps)
  Timeout.timeout(@timeout) do
    qry.each(fb, params, &)
  end
rescue Timeout::Error => e
  raise "each() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
end

#one(fb = @fb, params = {}) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/factbase/impatient.rb', line 68

def one(fb = @fb, params = {})
  qry = @fb.query(@term, @maps)
  Timeout.timeout(@timeout) do
    qry.one(fb, params)
  end
rescue Timeout::Error => e
  raise "one() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
end

#to_sObject



54
55
56
# File 'lib/factbase/impatient.rb', line 54

def to_s
  @term.to_s
end