Class: Tasker::Functions::FunctionWrapper
- Inherits:
-
Object
- Object
- Tasker::Functions::FunctionWrapper
show all
- Includes:
- ActiveModel::Attributes, ActiveModel::Model
- Defined in:
- lib/tasker/functions/function_wrapper.rb
Overview
Utility class for wrapping SQL function results in ActiveRecord-like objects
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.connection ⇒ Object
37
38
39
|
# File 'lib/tasker/functions/function_wrapper.rb', line 37
def self.connection
::Tasker::ApplicationRecord.connection
end
|
.convert_array_bind(bind) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/tasker/functions/function_wrapper.rb', line 24
def self.convert_array_bind(bind)
if bind.is_a?(Array)
"{#{bind.join(',')}}"
else
bind
end
end
|
.from_sql_function(sql, binds = [], name = nil) ⇒ Object
10
11
12
13
14
15
|
# File 'lib/tasker/functions/function_wrapper.rb', line 10
def self.from_sql_function(sql, binds = [], name = nil)
processed_binds = binds.map { |bind| convert_array_bind(bind) }
results = connection.select_all(sql, name, processed_binds)
results.map { |row| new(row) }
end
|
.single_from_sql_function(sql, binds = [], name = nil) ⇒ Object
17
18
19
20
21
22
|
# File 'lib/tasker/functions/function_wrapper.rb', line 17
def self.single_from_sql_function(sql, binds = [], name = nil)
processed_binds = binds.map { |bind| convert_array_bind(bind) }
result = connection.select_one(sql, name, processed_binds)
result ? new(result) : nil
end
|
Instance Method Details
#readonly? ⇒ Boolean
33
34
35
|
# File 'lib/tasker/functions/function_wrapper.rb', line 33
def readonly?
true
end
|