torque-postgresql 1.1.7 → 2.0.4

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.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/torque/postgresql.rb +0 -2
  3. data/lib/torque/postgresql/adapter.rb +7 -1
  4. data/lib/torque/postgresql/adapter/database_statements.rb +6 -15
  5. data/lib/torque/postgresql/adapter/oid.rb +3 -1
  6. data/lib/torque/postgresql/adapter/oid/box.rb +2 -0
  7. data/lib/torque/postgresql/adapter/oid/circle.rb +2 -0
  8. data/lib/torque/postgresql/adapter/oid/enum.rb +2 -0
  9. data/lib/torque/postgresql/adapter/oid/enum_set.rb +2 -0
  10. data/lib/torque/postgresql/adapter/oid/interval.rb +2 -0
  11. data/lib/torque/postgresql/adapter/oid/line.rb +2 -0
  12. data/lib/torque/postgresql/adapter/oid/range.rb +2 -0
  13. data/lib/torque/postgresql/adapter/oid/segment.rb +2 -0
  14. data/lib/torque/postgresql/adapter/quoting.rb +2 -0
  15. data/lib/torque/postgresql/adapter/schema_creation.rb +20 -23
  16. data/lib/torque/postgresql/adapter/schema_definitions.rb +9 -21
  17. data/lib/torque/postgresql/adapter/schema_dumper.rb +76 -11
  18. data/lib/torque/postgresql/adapter/schema_statements.rb +4 -12
  19. data/lib/torque/postgresql/arel/infix_operation.rb +5 -1
  20. data/lib/torque/postgresql/arel/join_source.rb +2 -0
  21. data/lib/torque/postgresql/arel/nodes.rb +2 -0
  22. data/lib/torque/postgresql/arel/operations.rb +2 -0
  23. data/lib/torque/postgresql/arel/select_manager.rb +2 -0
  24. data/lib/torque/postgresql/arel/visitors.rb +6 -3
  25. data/lib/torque/postgresql/associations.rb +0 -3
  26. data/lib/torque/postgresql/associations/association.rb +5 -1
  27. data/lib/torque/postgresql/associations/association_scope.rb +20 -60
  28. data/lib/torque/postgresql/associations/belongs_to_many_association.rb +5 -1
  29. data/lib/torque/postgresql/associations/builder/belongs_to_many.rb +2 -0
  30. data/lib/torque/postgresql/associations/builder/has_many.rb +2 -0
  31. data/lib/torque/postgresql/associations/preloader.rb +0 -32
  32. data/lib/torque/postgresql/associations/preloader/association.rb +42 -10
  33. data/lib/torque/postgresql/attributes/builder.rb +2 -0
  34. data/lib/torque/postgresql/attributes/builder/enum.rb +5 -3
  35. data/lib/torque/postgresql/attributes/builder/period.rb +6 -4
  36. data/lib/torque/postgresql/attributes/enum.rb +5 -10
  37. data/lib/torque/postgresql/attributes/enum_set.rb +2 -0
  38. data/lib/torque/postgresql/attributes/lazy.rb +3 -1
  39. data/lib/torque/postgresql/attributes/period.rb +2 -0
  40. data/lib/torque/postgresql/autosave_association.rb +9 -3
  41. data/lib/torque/postgresql/auxiliary_statement.rb +3 -13
  42. data/lib/torque/postgresql/auxiliary_statement/settings.rb +2 -0
  43. data/lib/torque/postgresql/base.rb +2 -0
  44. data/lib/torque/postgresql/coder.rb +6 -5
  45. data/lib/torque/postgresql/collector.rb +2 -0
  46. data/lib/torque/postgresql/config.rb +3 -4
  47. data/lib/torque/postgresql/geometry_builder.rb +2 -0
  48. data/lib/torque/postgresql/i18n.rb +2 -0
  49. data/lib/torque/postgresql/inheritance.rb +15 -17
  50. data/lib/torque/postgresql/migration/command_recorder.rb +2 -0
  51. data/lib/torque/postgresql/railtie.rb +2 -0
  52. data/lib/torque/postgresql/reflection.rb +2 -0
  53. data/lib/torque/postgresql/reflection/abstract_reflection.rb +28 -26
  54. data/lib/torque/postgresql/reflection/association_reflection.rb +2 -0
  55. data/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +6 -26
  56. data/lib/torque/postgresql/reflection/has_many_reflection.rb +2 -0
  57. data/lib/torque/postgresql/reflection/runtime_reflection.rb +2 -0
  58. data/lib/torque/postgresql/reflection/through_reflection.rb +2 -0
  59. data/lib/torque/postgresql/relation.rb +10 -11
  60. data/lib/torque/postgresql/relation/auxiliary_statement.rb +7 -8
  61. data/lib/torque/postgresql/relation/distinct_on.rb +3 -1
  62. data/lib/torque/postgresql/relation/inheritance.rb +2 -0
  63. data/lib/torque/postgresql/relation/merger.rb +2 -0
  64. data/lib/torque/postgresql/schema_cache.rb +2 -0
  65. data/lib/torque/postgresql/version.rb +3 -1
  66. data/spec/en.yml +19 -0
  67. data/spec/factories/authors.rb +6 -0
  68. data/spec/factories/comments.rb +13 -0
  69. data/spec/factories/posts.rb +6 -0
  70. data/spec/factories/tags.rb +5 -0
  71. data/spec/factories/texts.rb +5 -0
  72. data/spec/factories/users.rb +6 -0
  73. data/spec/factories/videos.rb +5 -0
  74. data/spec/mocks/cache_query.rb +16 -0
  75. data/spec/mocks/create_table.rb +35 -0
  76. data/spec/models/activity.rb +3 -0
  77. data/spec/models/activity_book.rb +4 -0
  78. data/spec/models/activity_post.rb +7 -0
  79. data/spec/models/activity_post/sample.rb +4 -0
  80. data/spec/models/author.rb +4 -0
  81. data/spec/models/author_journalist.rb +4 -0
  82. data/spec/models/comment.rb +3 -0
  83. data/spec/models/course.rb +2 -0
  84. data/spec/models/geometry.rb +2 -0
  85. data/spec/models/guest_comment.rb +4 -0
  86. data/spec/models/post.rb +6 -0
  87. data/spec/models/tag.rb +2 -0
  88. data/spec/models/text.rb +2 -0
  89. data/spec/models/time_keeper.rb +2 -0
  90. data/spec/models/user.rb +8 -0
  91. data/spec/models/video.rb +2 -0
  92. data/spec/schema.rb +141 -0
  93. data/spec/spec_helper.rb +59 -0
  94. data/spec/tests/arel_spec.rb +74 -0
  95. data/spec/tests/auxiliary_statement_spec.rb +593 -0
  96. data/spec/tests/belongs_to_many_spec.rb +246 -0
  97. data/spec/tests/coder_spec.rb +367 -0
  98. data/spec/tests/collector_spec.rb +59 -0
  99. data/spec/tests/distinct_on_spec.rb +65 -0
  100. data/spec/tests/enum_set_spec.rb +306 -0
  101. data/spec/tests/enum_spec.rb +628 -0
  102. data/spec/tests/geometric_builder_spec.rb +221 -0
  103. data/spec/tests/has_many_spec.rb +400 -0
  104. data/spec/tests/interval_spec.rb +167 -0
  105. data/spec/tests/lazy_spec.rb +24 -0
  106. data/spec/tests/period_spec.rb +954 -0
  107. data/spec/tests/quoting_spec.rb +24 -0
  108. data/spec/tests/range_spec.rb +36 -0
  109. data/spec/tests/relation_spec.rb +57 -0
  110. data/spec/tests/table_inheritance_spec.rb +416 -0
  111. metadata +102 -14
  112. data/lib/torque/postgresql/associations/join_dependency/join_association.rb +0 -15
  113. data/lib/torque/postgresql/schema_dumper.rb +0 -91
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Arel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Arel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Arel
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Arel
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Arel
4
6
  module Visitors
5
7
  # Enclose select manager with parenthesis
6
8
  # :TODO: Remove when checking the new version of Arel
7
- def visit_Arel_SelectManager o, collector
9
+ def visit_Arel_SelectManager(o, collector)
8
10
  collector << '('
9
11
  visit(o.ast, collector) << ')'
10
12
  end
@@ -23,8 +25,9 @@ module Torque
23
25
 
24
26
  # Allow quoted arrays to get here
25
27
  def visit_Arel_Nodes_Casted(o, collector)
26
- return super unless o.val.is_a?(::Enumerable)
27
- quote_array(o.val, collector)
28
+ value = o.respond_to?(:val) ? o.val : o.value
29
+ return super unless value.is_a?(::Enumerable)
30
+ quote_array(value, collector)
28
31
  end
29
32
 
30
33
  ## TORQUE VISITORS
@@ -3,6 +3,3 @@ require_relative 'associations/association_scope'
3
3
  require_relative 'associations/belongs_to_many_association'
4
4
  require_relative 'associations/builder'
5
5
  require_relative 'associations/preloader'
6
-
7
- require_relative 'associations/join_dependency/join_association' \
8
- unless Torque::PostgreSQL::AR521
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Associations
@@ -19,12 +21,14 @@ module Torque
19
21
  add_id = owner[reflection.active_record_primary_key]
20
22
  record_fk = reflection.foreign_key
21
23
 
22
- record[record_fk].push(add_id) unless (record[record_fk] ||= []).include?(add_id)
24
+ list = record[record_fk] ||= []
25
+ list.push(add_id) unless list.include?(add_id)
23
26
  end
24
27
 
25
28
  end
26
29
 
27
30
  ::ActiveRecord::Associations::Association.prepend(Association)
31
+ ::ActiveRecord::Associations::HasManyAssociation.prepend(Association)
28
32
  end
29
33
  end
30
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Associations
@@ -14,63 +16,40 @@ module Torque
14
16
  # When the relation is connected through an array, intercept the
15
17
  # condition builder and uses an overlap condition building it on
16
18
  # +build_id_constraint+
17
- def last_chain_scope(scope, *args)
18
- # 5.0 table, reflection, owner, association_klass
19
- # 5.1 table, reflection, owner
20
- # 5.2 reflection, owner
21
-
22
- reflection = args.size.eql?(2) ? args[0] : args[1]
19
+ def last_chain_scope(scope, reflection, owner)
23
20
  return super unless reflection.connected_through_array?
24
21
 
25
- table = args[0] if args.size > 2
26
- keys = args.size.eql?(4) ? reflection.join_keys(args[3]) : reflection.join_keys
27
- owner = args.size.eql?(2) ? args[1] : args[2]
28
-
22
+ keys = reflection.join_keys
29
23
  value = transform_value(owner[keys.foreign_key])
30
- constraint, binds = build_id_constraint(reflection, keys, value, table, true)
24
+ constraint = build_id_constraint(reflection, keys, value, true)
31
25
 
32
- if Torque::PostgreSQL::AR521
33
- scope.where!(constraint)
34
- else
35
- klass = ::ActiveRecord::Relation::WhereClause
36
- scope.where_clause += klass.new([constraint], binds)
37
- scope
38
- end
26
+ scope.where!(constraint)
39
27
  end
40
28
 
41
29
  # When the relation is connected through an array, intercept the
42
30
  # condition builder and uses an overlap condition building it on
43
31
  # +build_id_constraint+
44
- def next_chain_scope(scope, *args)
45
- # 5.0 table, reflection, association_klass, foreign_table, next_reflection
46
- # 5.1 table, reflection, foreign_table, next_reflection
47
- # 5.2 reflection, next_reflection
48
-
49
- reflection = args.size.eql?(2) ? args[0] : args[1]
32
+ def next_chain_scope(scope, reflection, next_reflection)
50
33
  return super unless reflection.connected_through_array?
51
34
 
52
- table = args[0] if args.size > 2
53
- next_reflection = args[-1]
54
-
55
- foreign_table = args[-2] if args.size.eql?(5)
56
- foreign_table ||= next_reflection.aliased_table
57
-
58
- keys = args.size.eql?(5) ? reflection.join_keys(args[2]) : reflection.join_keys
35
+ keys = reflection.join_keys
36
+ foreign_table = next_reflection.aliased_table
59
37
 
60
38
  value = foreign_table[keys.foreign_key]
61
- constraint, *_ = build_id_constraint(reflection, keys, value, table)
39
+ constraint = build_id_constraint(reflection, keys, value)
62
40
 
63
41
  scope.joins!(join(foreign_table, constraint))
64
42
  end
65
43
 
66
44
  # Trigger the same method on the relation which will build the
67
45
  # constraint condition using array logics
68
- def build_id_constraint(reflection, keys, value, table = nil, bind_param = false)
69
- table ||= reflection.aliased_table
70
- value, binds = build_binds_for_constraint(reflection, value, keys.foreign_key) \
71
- if bind_param
46
+ def build_id_constraint(reflection, keys, value, bind_param = false)
47
+ table = reflection.aliased_table
48
+ value = Array.wrap(value).map do |value|
49
+ build_bind_param_for_constraint(reflection, value, keys.foreign_key)
50
+ end if bind_param
72
51
 
73
- [reflection.build_id_constraint(table[keys.key], value), binds]
52
+ reflection.build_id_constraint(table[keys.key], value)
74
53
  end
75
54
 
76
55
  # For array-like values, it needs to call the method as many times as
@@ -83,30 +62,11 @@ module Torque
83
62
  end
84
63
  end
85
64
 
86
- # When binds are necessary for a constraint, instantiate them
87
- if Torque::PostgreSQL::AR521
88
- def build_binds_for_constraint(reflection, values, foreign_key)
89
- result = Array.wrap(values).map do |value|
90
- ::Arel::Nodes::BindParam.new(::ActiveRecord::Relation::QueryAttribute.new(
91
- foreign_key, value, reflection.klass.attribute_types[foreign_key],
92
- ))
93
- end
94
-
95
- [result, nil]
96
- end
97
- else
98
- def build_binds_for_constraint(reflection, values, foreign_key)
99
- type = reflection.klass.attribute_types[foreign_key]
100
- parts = Array.wrap(values).map do |value|
101
- bind = ::Arel::Nodes::BindParam.new
102
- value = ::ActiveRecord::Relation::QueryAttribute.new(foreign_key, value, type)
103
- [bind, value]
104
- end.to_h
105
-
106
- [parts.keys, parts.values]
107
- end
65
+ def build_bind_param_for_constraint(reflection, value, foreign_key)
66
+ ::Arel::Nodes::BindParam.new(::ActiveRecord::Relation::QueryAttribute.new(
67
+ foreign_key, value, reflection.klass.attribute_types[foreign_key],
68
+ ))
108
69
  end
109
-
110
70
  end
111
71
 
112
72
  ::ActiveRecord::Associations::AssociationScope.singleton_class.prepend(AssociationScope::ClassMethods)
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record/associations/collection_association'
4
+
2
5
  # FIXME: build, create
3
6
  module Torque
4
7
  module PostgreSQL
@@ -33,7 +36,8 @@ module Torque
33
36
 
34
37
  def ids_writer(new_ids)
35
38
  column = source_attr
36
- owner.update_column(column, owner[column] = new_ids.presence)
39
+ command = owner.persisted? ? :update_column : :write_attribute
40
+ owner.public_send(command, column, new_ids.presence)
37
41
  @association_scope = nil
38
42
  end
39
43
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Associations
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Associations
@@ -1,33 +1 @@
1
1
  require_relative 'preloader/association'
2
-
3
- unless Torque::PostgreSQL::AR521
4
- module Torque
5
- module PostgreSQL
6
- module Associations
7
- module Preloader
8
- class BelongsToMany < ::ActiveRecord::Associations::Preloader::HasMany
9
- def association_key_name
10
- reflection.active_record_primary_key
11
- end
12
-
13
- def owner_key_name
14
- reflection.foreign_key
15
- end
16
- end
17
-
18
- def preloader_for(reflection, owners, *)
19
- return AlreadyLoaded \
20
- if owners.first.association(reflection.name).loaded?
21
-
22
- return BelongsToMany \
23
- if reflection.macro.eql?(:belongs_to_many)
24
-
25
- super
26
- end
27
- end
28
-
29
- ::ActiveRecord::Associations::Preloader.prepend(Preloader)
30
- end
31
- end
32
- end
33
- end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Associations
@@ -8,7 +10,7 @@ module Torque
8
10
 
9
11
  # For reflections connected through an array, make sure to properly
10
12
  # decuple the list of ids and set them as associated with the owner
11
- def run(preloader)
13
+ def run
12
14
  return super unless connected_through_array?
13
15
  send("run_array_for_#{@reflection.macro}")
14
16
  end
@@ -18,7 +20,7 @@ module Torque
18
20
  # Specific run for belongs_many association
19
21
  def run_array_for_belongs_to_many
20
22
  # Add reverse to has_many
21
- records = load_records
23
+ records = groupped_records
22
24
  owners.each do |owner|
23
25
  items = records.values_at(*Array.wrap(owner[owner_key_name]))
24
26
  associate_records_to_owner(owner, items.flatten)
@@ -29,7 +31,7 @@ module Torque
29
31
  def run_array_for_has_many
30
32
  # Add reverse to belongs_to_many
31
33
  records = Hash.new { |h, k| h[k] = [] }
32
- load_records.each do |ids, record|
34
+ groupped_records.each do |ids, record|
33
35
  ids.each { |id| records[id].concat(Array.wrap(record)) }
34
36
  end
35
37
 
@@ -38,23 +40,53 @@ module Torque
38
40
  end
39
41
  end
40
42
 
43
+ if PostgreSQL::AR610
44
+ # This is how Rails 6.1 now load the records
45
+ def load_records
46
+ return super unless connected_through_array?
47
+
48
+ @records_by_owner = {}.compare_by_identity
49
+ raw_records = owner_keys.empty? ? [] : records_for(owner_keys)
50
+
51
+ @preloaded_records = raw_records.select do |record|
52
+ assignments = false
53
+
54
+ ids = convert_key(record[association_key_name])
55
+ owners_by_key.values_at(*ids).flat_map do |owner|
56
+ entries = (@records_by_owner[owner] ||= [])
57
+
58
+ if reflection.collection? || entries.empty?
59
+ entries << record
60
+ assignments = true
61
+ end
62
+ end
63
+
64
+ assignments
65
+ end
66
+ end
67
+ end
68
+
41
69
  # Build correctly the constraint condition in order to get the
42
70
  # associated ids
43
71
  def records_for(ids, &block)
44
72
  return super unless connected_through_array?
45
- condition = scope.arel_attribute(association_key_name)
73
+ condition = scope.arel_table[association_key_name]
46
74
  condition = reflection.build_id_constraint(condition, ids.flatten.uniq)
47
75
  scope.where(condition).load(&block)
48
76
  end
49
77
 
50
- unless Torque::PostgreSQL::AR521
51
- def associate_records_to_owner(owner, records)
52
- association = owner.association(reflection.name)
53
- association.loaded!
54
- association.target.concat(records)
55
- end
78
+ def associate_records_to_owner(owner, records)
79
+ return super unless connected_through_array?
80
+ association = owner.association(reflection.name)
81
+ association.loaded!
82
+ association.target.concat(records)
56
83
  end
57
84
 
85
+ def groupped_records
86
+ preloaded_records.group_by do |record|
87
+ convert_key(record[association_key_name])
88
+ end
89
+ end
58
90
  end
59
91
 
60
92
  ::ActiveRecord::Associations::Preloader::Association.prepend(Association)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'builder/enum'
2
4
  require_relative 'builder/period'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Attributes
@@ -153,12 +155,12 @@ module Torque
153
155
  cast_type = subtype.name.chomp('[]')
154
156
  klass_module.module_eval <<-RUBY, __FILE__, __LINE__ + 1
155
157
  def has_#{attribute.pluralize}(*values) # def has_roles(*values)
156
- attr = arel_attribute('#{attribute}') # attr = arel_attribute('role')
158
+ attr = arel_table['#{attribute}'] # attr = arel_table['role']
157
159
  where(attr.contains(::Arel.array(values, cast: '#{cast_type}'))) # where(attr.contains(::Arel.array(values, cast: 'roles')))
158
160
  end # end
159
161
 
160
162
  def has_any_#{attribute.pluralize}(*values) # def has_roles(*values)
161
- attr = arel_attribute('#{attribute}') # attr = arel_attribute('role')
163
+ attr = arel_table['#{attribute}'] # attr = arel_table['role']
162
164
  where(attr.overlaps(::Arel.array(values, cast: '#{cast_type}'))) # where(attr.overlaps(::Arel.array(values, cast: 'roles')))
163
165
  end # end
164
166
  RUBY
@@ -184,7 +186,7 @@ module Torque
184
186
  values_methods.each do |key, (scope, ask, bang, val)|
185
187
  klass_content += <<-RUBY
186
188
  def #{scope} # def admin
187
- attr = arel_attribute('#{attribute}') # attr = arel_attribute('role')
189
+ attr = arel_table['#{attribute}'] # attr = arel_table['role']
188
190
  where(::#{enum_klass}.scope(attr, '#{val}')) # where(Enum::Roles.scope(attr, 'admin'))
189
191
  end # end
190
192
  RUBY
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Attributes
@@ -202,7 +204,7 @@ module Torque
202
204
  end
203
205
 
204
206
  def arel_attribute
205
- @arel_attribute ||= "arel_attribute(#{attribute.inspect})"
207
+ @arel_attribute ||= "arel_table[#{attribute.inspect}]"
206
208
  end
207
209
 
208
210
  def arel_default_sql
@@ -245,7 +247,7 @@ module Torque
245
247
  def arel_real_start_at
246
248
  return arel_start_at unless threshold.present?
247
249
  @arel_real_start_at ||= begin
248
- result = "(#{arel_start_at} - #{arel_threshold_value})"
250
+ result = +"(#{arel_start_at} - #{arel_threshold_value})"
249
251
  result << '.cast(:date)' if type.eql?(:daterange)
250
252
  result
251
253
  end
@@ -255,7 +257,7 @@ module Torque
255
257
  def arel_real_finish_at
256
258
  return arel_finish_at unless threshold.present?
257
259
  @arel_real_finish_at ||= begin
258
- result = "(#{arel_finish_at} + #{arel_threshold_value})"
260
+ result = +"(#{arel_finish_at} + #{arel_threshold_value})"
259
261
  result << '.cast(:date)' if type.eql?(:daterange)
260
262
  result
261
263
  end
@@ -276,7 +278,7 @@ module Torque
276
278
 
277
279
  # Create an arel named function
278
280
  def arel_named_function(name, *args)
279
- result = "::Arel::Nodes::NamedFunction.new(#{name.to_s.inspect}"
281
+ result = +"::Arel::Nodes::NamedFunction.new(#{name.to_s.inspect}"
280
282
  result << ', [' << args.join(', ') << ']' if args.present?
281
283
  result << ')'
282
284
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Torque
2
4
  module PostgreSQL
3
5
  module Attributes
@@ -31,11 +33,6 @@ module Torque
31
33
  end
32
34
  end
33
35
 
34
- # You can specify the connection name for each enum
35
- def connection_specification_name
36
- return self == Enum ? 'primary' : superclass.connection_specification_name
37
- end
38
-
39
36
  # Overpass new so blank values return only nil
40
37
  def new(value)
41
38
  return Lazy.new(self, LAZY_VALUE) if value.blank?
@@ -45,9 +42,7 @@ module Torque
45
42
  # Load the list of values in a lazy way
46
43
  def values
47
44
  @values ||= self == Enum ? nil : begin
48
- conn_name = connection_specification_name
49
- conn = connection(conn_name)
50
- conn.enum_values(type_name).freeze
45
+ connection.enum_values(type_name).freeze
51
46
  end
52
47
  end
53
48
 
@@ -110,8 +105,8 @@ module Torque
110
105
  end
111
106
 
112
107
  # Get a connection based on its name
113
- def connection(name)
114
- ActiveRecord::Base.connection_handler.retrieve_connection(name)
108
+ def connection
109
+ ::ActiveRecord::Base.connection
115
110
  end
116
111
 
117
112
  end