Class: Simple::SQL::Result

Inherits:
Array
  • Object
show all
Defined in:
lib/simple/sql/result.rb,
lib/simple/sql/result.rb

Overview

The result of SQL.all

This class implements the basic interface of a Result set. Record result sets support the conversion of a record into a custom type of the callers choice, via the :into option for SQL.all and SQL.ask.

Direct Known Subclasses

Records

Defined Under Namespace

Modules: AssociationLoader Classes: Records

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ Result

:nodoc:



30
31
32
# File 'lib/simple/sql/result.rb', line 30

def initialize(records) # :nodoc:
  replace(records)
end

Instance Attribute Details

#current_pageObject (readonly)

returns the current page number in a paginated search

This is filled in when resolving a paginated scope.



48
49
50
# File 'lib/simple/sql/result.rb', line 48

def current_page
  @current_page
end

#total_countObject (readonly)

returns the total_count of search hits

This is filled in when resolving a paginated scope.



37
38
39
# File 'lib/simple/sql/result.rb', line 37

def total_count
  @total_count
end

#total_pagesObject (readonly)

returns the total number of pages of search hits

This is filled in when resolving a paginated scope. It takes into account the scope’s “per” option.



43
44
45
# File 'lib/simple/sql/result.rb', line 43

def total_pages
  @total_pages
end

Class Method Details

.build(records, target_type:, pg_source_oid:) ⇒ Object

A Result object is requested via ::Simple::SQL::Result.build, which then chooses the correct implementation, based on the target_type: parameter.



22
23
24
25
26
27
28
# File 'lib/simple/sql/result.rb', line 22

def self.build(records, target_type:, pg_source_oid:) # :nodoc:
  if target_type.nil?
    new(records)
  else
    Records.new(records, target_type: target_type, pg_source_oid: pg_source_oid)
  end
end