torque-postgresql 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 261ea2ffc412c3f06c841be868141f631fa9f983
|
4
|
+
data.tar.gz: e5f58518bcc173eaa8be19ea24e25f086546e78c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2742264fd62ee56eea953349bd95dc441d37948e2ebce6e8acb69ec200aabab5ca95e016ad7654b6626fc4bac465797abf88e3bd259f5149f2e3d60f74cae566
|
7
|
+
data.tar.gz: 879d2eb8e794009a63f1d69ea85b967a126709b242cee0fd9ccac6d1ad4734e8ca62aa69413c708b47c692557e1b935ed759562caebae56bc48e85afe3269bc9
|
data/Rakefile
CHANGED
@@ -14,13 +14,16 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
15
|
end
|
16
16
|
|
17
|
-
desc '
|
18
|
-
task :
|
17
|
+
desc 'Initialize the local environment'
|
18
|
+
task :environment do |t|
|
19
19
|
lib = File.expand_path('../lib', __FILE__)
|
20
20
|
spec = File.expand_path('../spec', __FILE__)
|
21
21
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
22
22
|
$LOAD_PATH.unshift(spec) unless $LOAD_PATH.include?(spec)
|
23
|
+
end
|
23
24
|
|
25
|
+
desc 'Prints a schema dump of the test database'
|
26
|
+
task dump: :environment do |t|
|
24
27
|
require 'byebug'
|
25
28
|
require 'spec_helper'
|
26
29
|
ActiveRecord::SchemaDumper.dump
|
@@ -11,6 +11,7 @@ module Torque
|
|
11
11
|
@data_sources_model_names = {}
|
12
12
|
@inheritance_dependencies = {}
|
13
13
|
@inheritance_associations = {}
|
14
|
+
@inheritance_loaded = false
|
14
15
|
end
|
15
16
|
|
16
17
|
def initialize_dup(*) # :nodoc:
|
@@ -22,16 +23,16 @@ module Torque
|
|
22
23
|
|
23
24
|
def encode_with(coder) # :nodoc:
|
24
25
|
super
|
25
|
-
coder[
|
26
|
-
coder[
|
27
|
-
coder[
|
26
|
+
coder['data_sources_model_names'] = @data_sources_model_names
|
27
|
+
coder['inheritance_dependencies'] = @inheritance_dependencies
|
28
|
+
coder['inheritance_associations'] = @inheritance_associations
|
28
29
|
end
|
29
30
|
|
30
31
|
def init_with(coder) # :nodoc:
|
31
32
|
super
|
32
|
-
@data_sources_model_names = coder[
|
33
|
-
@inheritance_dependencies = coder[
|
34
|
-
@inheritance_associations = coder[
|
33
|
+
@data_sources_model_names = coder['data_sources_model_names']
|
34
|
+
@inheritance_dependencies = coder['inheritance_dependencies']
|
35
|
+
@inheritance_associations = coder['inheritance_associations']
|
35
36
|
end
|
36
37
|
|
37
38
|
def add(table_name, *) # :nodoc:
|
@@ -41,6 +42,7 @@ module Torque
|
|
41
42
|
if @data_sources.key?(table_name)
|
42
43
|
@inheritance_dependencies.clear
|
43
44
|
@inheritance_associations.clear
|
45
|
+
@inheritance_loaded = false
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -49,6 +51,7 @@ module Torque
|
|
49
51
|
@data_sources_model_names.clear
|
50
52
|
@inheritance_dependencies.clear
|
51
53
|
@inheritance_associations.clear
|
54
|
+
@inheritance_loaded = false
|
52
55
|
end
|
53
56
|
|
54
57
|
def size # :nodoc:
|
@@ -71,10 +74,12 @@ module Torque
|
|
71
74
|
@inheritance_dependencies,
|
72
75
|
@inheritance_associations,
|
73
76
|
@data_sources_model_names,
|
77
|
+
@inheritance_loaded,
|
74
78
|
]
|
75
79
|
end
|
76
80
|
|
77
81
|
def marshal_load(array) # :nodoc:
|
82
|
+
@inheritance_loaded = array.pop
|
78
83
|
@data_sources_model_names = array.pop
|
79
84
|
@inheritance_associations = array.pop
|
80
85
|
@inheritance_dependencies = array.pop
|
@@ -101,13 +106,13 @@ module Torque
|
|
101
106
|
end
|
102
107
|
|
103
108
|
# Try to find a model based on a given table
|
104
|
-
def lookup_model(table_name,
|
105
|
-
|
109
|
+
def lookup_model(table_name, scoped_class = '')
|
110
|
+
scoped_class = scoped_class.name if scoped_class.is_a?(Class)
|
106
111
|
return @data_sources_model_names[table_name] \
|
107
112
|
if @data_sources_model_names.key?(table_name)
|
108
113
|
|
109
114
|
# Get all the possible scopes
|
110
|
-
scopes =
|
115
|
+
scopes = scoped_class.scan(/(?:::)?[A-Z][a-z]+/)
|
111
116
|
scopes.unshift('Object::')
|
112
117
|
|
113
118
|
# Consider the maximum namespaced possible model name
|
@@ -164,14 +169,17 @@ module Torque
|
|
164
169
|
# Reload information about tables inheritance and dependencies, uses a
|
165
170
|
# cache to not perform additional checkes
|
166
171
|
def reload_inheritance_data!
|
167
|
-
return if @
|
172
|
+
return if @inheritance_loaded
|
168
173
|
@inheritance_dependencies = connection.inherited_tables
|
169
174
|
@inheritance_associations = generate_associations
|
175
|
+
@inheritance_loaded = true
|
170
176
|
end
|
171
177
|
|
172
178
|
# Calculates the inverted dependency (association), where even indirect
|
173
179
|
# inheritance comes up in the list
|
174
180
|
def generate_associations
|
181
|
+
return {} if @inheritance_dependencies.empty?
|
182
|
+
|
175
183
|
result = Hash.new{ |h, k| h[k] = [] }
|
176
184
|
masters = @inheritance_dependencies.values.flatten.uniq
|
177
185
|
|
@@ -200,7 +208,7 @@ module Torque
|
|
200
208
|
super
|
201
209
|
@data_sources_model_names = Torque::PostgreSQL.config
|
202
210
|
.irregular_models.slice(*@data_sources.keys).map do |table_name, model_name|
|
203
|
-
[table_name, model_name.constantize]
|
211
|
+
[table_name, (model_name.is_a?(Class) ? model_name : model_name.constantize)]
|
204
212
|
end.to_h
|
205
213
|
end
|
206
214
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torque-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|