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
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
52
53
54
|
# File 'lib/sql_runner/query.rb', line 52
def self.call(**bind_vars)
execute(query, **bind_vars)
end
|
.connection_pool ⇒ Object
43
44
45
|
# File 'lib/sql_runner/query.rb', line 43
def self.connection_pool
@connection_pool || SQLRunner.connection_pool
end
|
.inherited(subclass) ⇒ Object
16
17
18
19
20
|
# File 'lib/sql_runner/query.rb', line 16
def self.inherited(subclass)
super
subclass.instance_variable_set(:@connection_pool, @connection_pool)
subclass.instance_variable_set(:@root_dir, @root_dir)
end
|
.plugin(*names) ⇒ Object
60
61
62
|
# File 'lib/sql_runner/query.rb', line 60
def self.plugin(*names)
plugins(*names)
end
|
.plugins(*names) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/sql_runner/query.rb', line 64
def self.plugins(*names)
names = prepare_plugins_with_options(names)
names.each do |name, options|
plugin = SQLRunner.plugin_registry.fetch(name) do
raise PluginNotFound, "#{name.inspect} wasn't found"
end
plugin.activate(self, options)
end
end
|
.prepare_plugins_with_options(plugins) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/sql_runner/query.rb', line 76
def self.prepare_plugins_with_options(plugins)
return plugins unless plugins.last.is_a?(Hash)
plugins_with_options = plugins.pop
plugins_with_options.each do |(name, options)|
plugins << [name.to_sym, options]
end
plugins
end
|
.query(*value) ⇒ Object
38
39
40
41
|
# File 'lib/sql_runner/query.rb', line 38
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
22
23
24
25
|
# File 'lib/sql_runner/query.rb', line 22
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
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/sql_runner/query.rb', line 27
def self.query_name_from_class
replacer = proc do
"#{Regexp.last_match(1)}_#{Regexp.last_match(2).downcase}"
end
name
.gsub("::", "/")
.gsub(/([a-z0-9])([A-Z])/, &replacer)
.downcase
end
|
.register_plugin(name, mod) ⇒ Object
56
57
58
|
# File 'lib/sql_runner/query.rb', line 56
def self.register_plugin(name, mod)
SQLRunner.plugin_registry[name] = mod
end
|
.root_dir(*value) ⇒ Object
47
48
49
50
|
# File 'lib/sql_runner/query.rb', line 47
def self.root_dir(*value)
@root_dir = value.first if value.any?
@root_dir || SQLRunner.root_dir
end
|