Class: Kweerie::BaseObject

Inherits:
Base
  • Object
show all
Defined in:
lib/kweerie/base_object.rb

Class Method Summary collapse

Methods inherited from Base

all, bind, inherited, sql_content, sql_file_location, sql_path

Class Method Details

.cast_definitionsObject



24
25
26
# File 'lib/kweerie/base_object.rb', line 24

def cast_definitions
  @cast_definitions ||= {}
end

.cast_select(field, as: nil) ⇒ Object



20
21
22
# File 'lib/kweerie/base_object.rb', line 20

def cast_select(field, as: nil)
  cast_definitions[field] = as if as
end

.with(params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/kweerie/base_object.rb', line 9

def with(params = {})
  results = super
  return [] if results.empty?

  # Create a unique result class for this query
  result_class = generate_result_class(results.first.keys)

  # Map results to objects
  results.map { |row| result_class.new(row) }
end