Class: SQLRunner::Query
- Inherits:
-
Object
show all
- Extended by:
- Runner
- Defined in:
- lib/sql_runner/query.rb,
lib/sql_runner/query/one.rb,
lib/sql_runner/query/many.rb,
lib/sql_runner/query/model.rb
Defined Under Namespace
Modules: Many, Model, One
Constant Summary
collapse
- PLUGINS =
{}
Class Method Summary
collapse
Methods included from Runner
execute
Methods included from Connection
#connect, #connection_pool, #disconnect, #with_connection
Class Method Details
.call(**bind_vars) ⇒ Object
37
38
39
|
# File 'lib/sql_runner/query.rb', line 37
def self.call(**bind_vars)
execute(query, **bind_vars)
end
|
.connection_pool ⇒ Object
28
29
30
|
# File 'lib/sql_runner/query.rb', line 28
def self.connection_pool
@connection_pool || SQLRunner.connection_pool
end
|
.plugin(*names) ⇒ Object
45
46
47
|
# File 'lib/sql_runner/query.rb', line 45
def self.plugin(*names)
plugins *names
end
|
.plugins(*names) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/sql_runner/query.rb', line 49
def self.plugins(*names)
names = prepare_plugins_with_options(names)
names.each do |name, options|
plugin = PLUGINS.fetch(name) { fail PluginNotFound, "#{name.inspect} wasn't found" }
plugin.activate(self, options)
end
end
|
.prepare_plugins_with_options(plugins) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/sql_runner/query.rb', line 58
def self.prepare_plugins_with_options(plugins)
return plugins unless plugins.last.kind_of?(Hash)
plugins_with_options = plugins.pop
plugins_with_options.each do |(name, options)|
plugins << [name.to_sym, options]
end
plugins
end
|
.query(*value) ⇒ Object
23
24
25
26
|
# File 'lib/sql_runner/query.rb', line 23
def self.query(*value)
@query = value.first if value.any?
@query || (@query = File.read(File.join(root_dir, "#{query_name}.sql")))
end
|
.query_name(*values) ⇒ Object
11
12
13
14
|
# File 'lib/sql_runner/query.rb', line 11
def self.query_name(*values)
@query_name = values.first if values.any?
@query_name || (@query_name = query_name_from_class)
end
|
.query_name_from_class ⇒ Object
16
17
18
19
20
21
|
# File 'lib/sql_runner/query.rb', line 16
def self.query_name_from_class
name
.gsub("::", "/")
.gsub(/([a-z0-9])([A-Z])/) { "#{$1}_#{$2.downcase}" }
.downcase
end
|
.register_plugin(name, mod) ⇒ Object
41
42
43
|
# File 'lib/sql_runner/query.rb', line 41
def self.register_plugin(name, mod)
PLUGINS[name] = mod
end
|
.root_dir(*value) ⇒ Object
32
33
34
35
|
# File 'lib/sql_runner/query.rb', line 32
def self.root_dir(*value)
@root_dir = value.first if value.any?
@root_dir || SQLRunner.root_dir
end
|