Class: Baza::Driver::ActiveRecord::Result

Inherits:
ResultBase
  • Object
show all
Defined in:
lib/baza/driver/active_record/result.rb

Instance Method Summary collapse

Methods inherited from ResultBase

#to_a, #to_a_enum, #to_enum

Constructor Details

#initialize(driver, result) ⇒ Result

Returns a new instance of Result.



2
3
4
5
# File 'lib/baza/driver/active_record/result.rb', line 2

def initialize(driver, result)
  @result = result
  @type_translation = driver.db.opts[:type_translation]
end

Instance Method Details

#eachObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/baza/driver/active_record/result.rb', line 13

def each
  return unless @result

  @result.each do |result|
    result = result.delete_if { |k, _v| k.is_a?(Fixnum) } # Seems like this happens depending on the version installed? - kaspernj
    result = Hash[result.map { |k, v| [k, v.to_s] }] if @type_translation == :string

    yield result.symbolize_keys
  end
end

#fetchObject



7
8
9
10
11
# File 'lib/baza/driver/active_record/result.rb', line 7

def fetch
  return to_enum.next
rescue StopIteration
  return false
end