torque-postgresql 1.1.1 → 1.1.6

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
- SHA1:
3
- metadata.gz: b95a55ebfe82e5b96582da09307f1d45d62ba922
4
- data.tar.gz: 38a068ec3fa7cc5aab2425a31e8ed37a49b15132
2
+ SHA256:
3
+ metadata.gz: 302ae61bb97f2666a7c1ada70d7b3ff2a2c5e9dd5230438fe8746ddf5933dcb3
4
+ data.tar.gz: 96771655afc7ea3a863c1069783e42858e7e27539e98724eb428f0d8d759ceb5
5
5
  SHA512:
6
- metadata.gz: b708c73cfcac1798474e35099570e4def16a6a51b2448ef34ce2ec5e97dd4c8d57f48fa51f18182f0405afa7eed1884b81846cb3b2e132b638c8711ee80dd72c
7
- data.tar.gz: 7bab6bd30e0b3898826b20cce99ff629192ea62d772864e10a3fc141e86e5f3f27a0f9e459addc29a8a27bcbb7df17920831d0f7e7b01ac823d65f600b699530
6
+ metadata.gz: 4da7ce39ab52a21dc00a0b1922e02296f96ffb3c4b8fe3c9c8e590a25482a9d04c17ab348e7da00259e5ae4c53865b512740d21e8bdf1f60c069955f4e58350e
7
+ data.tar.gz: 5309c59fc60b31a0c4e37056e836951b4f9652104c757b687be9f5c93ddb8629ed0f5ad8de054dd84a5a7f5d4ec9b8527a767c6f6a8776527d91e94eb5cba15d
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 'Prints a schema dump of the test database'
18
- task :dump do |t|
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
@@ -20,7 +20,6 @@ module Torque
20
20
  # 5.2 reflection, owner
21
21
 
22
22
  reflection = args.size.eql?(2) ? args[0] : args[1]
23
- puts reflection.connected_through_array?.inspect
24
23
  return super unless reflection.connected_through_array?
25
24
 
26
25
  table = args[0] if args.size > 2
@@ -31,11 +31,12 @@ module Torque
31
31
  end
32
32
 
33
33
  # Fast access to statement build
34
- def build(statement, base, options = nil, bound_attributes = [])
34
+ def build(statement, base, options = nil, bound_attributes = [], join_sources = [])
35
35
  klass = instantiate(statement, base, options)
36
36
  result = klass.build(base)
37
37
 
38
38
  bound_attributes.concat(klass.bound_attributes)
39
+ join_sources.concat(klass.join_sources)
39
40
  result
40
41
  end
41
42
 
@@ -105,7 +106,7 @@ module Torque
105
106
  delegate :config, :table, :table_name, :relation, :configure, :relation_query?,
106
107
  to: :class
107
108
 
108
- attr_reader :bound_attributes
109
+ attr_reader :bound_attributes, :join_sources
109
110
 
110
111
  # Start a new auxiliary statement giving extra options
111
112
  def initialize(*args)
@@ -117,15 +118,21 @@ module Torque
117
118
  @where = options.fetch(:where, {})
118
119
  @select = options.fetch(:select, {})
119
120
  @join_type = options.fetch(:join_type, nil)
121
+
120
122
  @bound_attributes = []
123
+ @join_sources = []
121
124
  end
122
125
 
123
126
  # Build the statement on the given arel and return the WITH statement
124
127
  def build(base)
128
+ @bound_attributes.clear
129
+ @join_sources.clear
130
+
131
+ # Prepare all the data for the statement
125
132
  prepare(base)
126
133
 
127
134
  # Add the join condition to the list
128
- base.joins_values += [build_join(base)]
135
+ @join_sources << build_join(base)
129
136
 
130
137
  # Return the statement with its dependencies
131
138
  [@dependencies, ::Arel::Nodes::As.new(table, build_query(base))]
@@ -288,7 +295,7 @@ module Torque
288
295
  cte.is_a?(dependent_klass)
289
296
  end
290
297
 
291
- AuxiliaryStatement.build(dependent, base, options, bound_attributes)
298
+ AuxiliaryStatement.build(dependent, base, options, bound_attributes, join_sources)
292
299
  end
293
300
  end
294
301
 
@@ -47,16 +47,16 @@ module Torque
47
47
 
48
48
  # Hook arel build to add the distinct on clause
49
49
  def build_arel(*)
50
- subqueries = build_auxiliary_statements
51
- return super if subqueries.nil?
52
- super.with(subqueries)
50
+ arel = super
51
+ subqueries = build_auxiliary_statements(arel)
52
+ subqueries.nil? ? arel : arel.with(subqueries)
53
53
  end
54
54
 
55
55
  # Build all necessary data for auxiliary statements
56
- def build_auxiliary_statements
57
- return unless self.auxiliary_statements_values.present?
58
- self.auxiliary_statements_values.map do |klass|
59
- klass.build(self)
56
+ def build_auxiliary_statements(arel)
57
+ return unless auxiliary_statements_values.present?
58
+ auxiliary_statements_values.map do |klass|
59
+ klass.build(self).tap { arel.join_sources.concat(klass.join_sources) }
60
60
  end
61
61
  end
62
62
 
@@ -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["data_sources_model_names"] = @data_sources_model_names
26
- coder["inheritance_dependencies"] = @inheritance_dependencies
27
- coder["inheritance_associations"] = @inheritance_associations
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["data_sources_model_names"]
33
- @inheritance_dependencies = coder["inheritance_dependencies"]
34
- @inheritance_associations = coder["inheritance_associations"]
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, scopred_class = '')
105
- scopred_class = scopred_class.name if scopred_class.is_a?(Class)
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 = scopred_class.scan(/(?:::)?[A-Z][a-z]+/)
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 @inheritance_dependencies.present?
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
 
@@ -31,21 +31,21 @@ module Torque
31
31
  if inherited_tables.present?
32
32
  stream.puts " # These are tables that has inheritance"
33
33
  inherited_tables.each do |table_name, inherits|
34
- unless ignored?(table_name)
35
- sub_stream = StringIO.new
36
- table(table_name, sub_stream)
37
-
38
- # Add the inherits setting
39
- sub_stream.rewind
40
- inherits.map!(&:to_sym)
41
- inherits = inherits.first if inherits.size === 1
42
- inherits = ", inherits: #{inherits.inspect} do |t|"
43
- table_dump = sub_stream.read.gsub(/ do \|t\|$/, inherits)
44
-
45
- # Ensure bodyless definitions
46
- table_dump.gsub!(/do \|t\|\n end/, '')
47
- stream.print table_dump
48
- end
34
+ next if ignored?(table_name)
35
+
36
+ sub_stream = StringIO.new
37
+ table(table_name, sub_stream)
38
+
39
+ # Add the inherits setting
40
+ sub_stream.rewind
41
+ inherits.map!(&:to_sym)
42
+ inherits = inherits.first if inherits.size === 1
43
+ inherits = ", inherits: #{inherits.inspect} do |t|"
44
+ table_dump = sub_stream.read.gsub(/ do \|t\|$/, inherits)
45
+
46
+ # Ensure bodyless definitions
47
+ table_dump.gsub!(/do \|t\|\n end/, '')
48
+ stream.print table_dump
49
49
  end
50
50
  end
51
51
 
@@ -55,6 +55,9 @@ module Torque
55
55
  foreign_keys(tbl, stream) unless ignored?(tbl)
56
56
  end
57
57
  end
58
+
59
+ # Scenic integration
60
+ views(stream) if defined?(::Scenic)
58
61
  end
59
62
 
60
63
  # Dump user defined types like enum
@@ -63,7 +66,7 @@ module Torque
63
66
  return unless types.any?
64
67
 
65
68
  stream.puts " # These are user-defined types used on this database"
66
- types.each { |name, type| send(type.to_sym, name, stream) }
69
+ types.sort_by(&:first).each { |name, type| send(type.to_sym, name, stream) }
67
70
  stream.puts
68
71
  rescue => e
69
72
  stream.puts "# Could not dump user-defined types because of following #{e.class}"
@@ -1,5 +1,5 @@
1
1
  module Torque
2
2
  module PostgreSQL
3
- VERSION = '1.1.1'
3
+ VERSION = '1.1.6'
4
4
  end
5
5
  end
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.1
4
+ version: 1.1.6
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-17 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -260,8 +260,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  - !ruby/object:Gem::Version
261
261
  version: 1.8.11
262
262
  requirements: []
263
- rubyforge_project:
264
- rubygems_version: 2.6.14
263
+ rubygems_version: 3.1.4
265
264
  signing_key:
266
265
  specification_version: 4
267
266
  summary: ActiveRecord extension to access PostgreSQL advanced resources