module Cassie::Statements::Results::Querying

Public Instance Methods

after_initialize(opts) click to toggle source
Calls superclass method
# File lib/cassie/statements/execution/results/querying.rb, line 21
def after_initialize(opts)
  super
  @each_deserializer = opts[:each_deserializer]
  @deserializer = opts[:deserializer]
  ensure_deserialization
end
each(&block) click to toggle source

Deserialize each row into domain objects

note: __object__.each is aliased as rows and each_row.

# File lib/cassie/statements/execution/results/querying.rb, line 32
def each(&block)
  if block_given?
    records.each(&block)
    self
  else
    records.each
  end
end
first!() click to toggle source
# File lib/cassie/statements/execution/results/querying.rb, line 41
def first!
  first || (raise Cassie::Statements::RecordNotFound, 'CQL row does not exist')
end
success?() click to toggle source
Calls superclass method
# File lib/cassie/statements/execution/results/querying.rb, line 45
def success?
  # an empty query is still successful
  return true if __getobj__.empty?

  super
end

Protected Instance Methods

ensure_deserialization() click to toggle source
# File lib/cassie/statements/execution/results/querying.rb, line 58
def ensure_deserialization
  @deserializer ||= method(each_deserializer ? :map_deserialize : :pass_through_deserialize)
end
map_deserialize(hashes) click to toggle source
# File lib/cassie/statements/execution/results/querying.rb, line 66
def map_deserialize(hashes)
  hashes.map{|hash| each_deserializer.call(hash) }
end
pass_through_deserialize(hashes) click to toggle source
# File lib/cassie/statements/execution/results/querying.rb, line 62
def pass_through_deserialize(hashes)
  hashes
end
records() click to toggle source
# File lib/cassie/statements/execution/results/querying.rb, line 54
def records
  @records ||= deserializer.call(rows)
end