torque-postgresql 0.2.12 → 0.2.13

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: e47edba535baccbfc619501bb245f4a32d794db6
4
- data.tar.gz: d46d270a45f3f03b3bbf5e2292de9cd199f21897
3
+ metadata.gz: 6a19c0e5178591e3b9ea84d11df0b21d34f135df
4
+ data.tar.gz: 06c0b78395434ae948854222ce3ad015ce55cd61
5
5
  SHA512:
6
- metadata.gz: 7948fc1d1f54cb902f4fc0778d5317e7b67ad059b16253171a389f5c43054117305819611c4a6d49e6939b36b727ed525154a4f01c7559468b9cc3c26582bff1
7
- data.tar.gz: 1c228d0856a13a1beef89e0fc811dfc80d73c208f46f164455a400ff6854b5d66269c7eaefe831ee72eed4de594010f4afcf9dfa893b3c0018a94ab0b5f032a8
6
+ metadata.gz: 90146d035616baa734f5a068028b32bf5a9605539d1f58a76f8ce107b65eeeaed8e88776d6bde29460ab340667b96a14fbf0e18f196c98d805f479511a5db167
7
+ data.tar.gz: f5f126cf74c95a4c3ccb4d6aab8f69c82a5e37215ea79928d2bc261f819d00db8c6721e059e954c9dd353182a74794c31668630ce58dac49f6274c5a113d919f
@@ -11,7 +11,7 @@ module Torque
11
11
  module Adapter
12
12
 
13
13
  include Quoting
14
- include ColumnDumper
14
+ include ColumnDumper unless Torque::PostgreSQL::AR521
15
15
  include DatabaseStatements
16
16
  include SchemaStatements
17
17
 
@@ -33,15 +33,26 @@ module Torque
33
33
  end
34
34
 
35
35
  # Change some of the types being mapped
36
- def initialize_type_map(m)
36
+ def initialize_type_map(m = type_map)
37
37
  super
38
38
  m.register_type 'interval', OID::Interval.new
39
39
  end
40
40
 
41
- # Add the composite types to be loaded too.
42
- def load_additional_types(type_map, oids = nil)
43
- super
41
+ # :nodoc:
42
+ if Torque::PostgreSQL::AR521
43
+ def load_additional_types(oids = nil)
44
+ super
45
+ torque_load_additional_types(oids)
46
+ end
47
+ else
48
+ def load_additional_types(type_map, oids = nil)
49
+ super
50
+ torque_load_additional_types(oids)
51
+ end
52
+ end
44
53
 
54
+ # Add the composite types to be loaded too.
55
+ def torque_load_additional_types(oids = nil)
45
56
  filter = "AND a.typelem::integer IN (%s)" % oids.join(", ") if oids
46
57
 
47
58
  query = <<-SQL
@@ -81,7 +81,7 @@ module Torque
81
81
  num = num.to_i unless num.is_a?(Numeric)
82
82
  if num > 0
83
83
  seconds += num.send(part).value
84
- [part, num]
84
+ [part.to_sym, num]
85
85
  end
86
86
  end
87
87
  ActiveSupport::Duration.new(seconds, parts.compact)
@@ -3,10 +3,16 @@ module Torque
3
3
  module Adapter
4
4
  module ColumnMethods
5
5
 
6
+ # Creates a column with an interval type, allowing span of times and
7
+ # dates to be stored without having to store a seconds-based integer
8
+ # or any sort of other approach
6
9
  def interval(*args, **options)
7
10
  args.each { |name| column(name, :interval, options) }
8
11
  end
9
12
 
13
+ # Creates a column with an enum type, needing to specify the subtype,
14
+ # which is basically the name of the type defined prior creating the
15
+ # column
10
16
  def enum(*args, **options)
11
17
  args.each do |name|
12
18
  type = options.fetch(:subtype, name)
@@ -21,7 +27,7 @@ module Torque
21
27
 
22
28
  attr_reader :inherits
23
29
 
24
- def initialize(name, *args, **options)
30
+ def initialize(name, *_, **options)
25
31
  old_args = []
26
32
  old_args << options.delete(:temporary) || false
27
33
  old_args << options.delete(:options)
@@ -4,8 +4,10 @@ module Torque
4
4
  module ColumnDumper
5
5
 
6
6
  # Adds +:subtype+ as a valid migration key
7
- def migration_keys
8
- super + [:subtype]
7
+ unless Torque::PostgreSQL::AR521
8
+ def migration_keys
9
+ super + [:subtype]
10
+ end
9
11
  end
10
12
 
11
13
  # Adds +:subtype+ option to the default set
@@ -22,7 +24,7 @@ module Torque
22
24
  private
23
25
 
24
26
  def schema_subtype(column)
25
- column.sql_type.to_sym.inspect if [:enum].include? column.type
27
+ column.sql_type.to_sym.inspect if column.type == :enum
26
28
  end
27
29
 
28
30
  end
@@ -2,6 +2,9 @@ module Torque
2
2
  module PostgreSQL
3
3
  include ActiveSupport::Configurable
4
4
 
5
+ # Stores a version check for compatibility purposes
6
+ AR521 = (ActiveRecord.gem_version >= Gem::Version.new('5.2.1'))
7
+
5
8
  # Allow nested configurations
6
9
  # :TODO: Rely on +inheritable_copy+ to make nested configurations
7
10
  config.define_singleton_method(:nested) do |name, &block|
@@ -76,7 +76,7 @@ module Torque
76
76
  @dynamic_selection ||= []
77
77
  end
78
78
 
79
- def build_arel
79
+ def build_arel(*)
80
80
  arel = super
81
81
  arel.project(*dynamic_selection) if select_values.blank? && dynamic_selection.any?
82
82
  arel
@@ -33,15 +33,20 @@ module Torque
33
33
  # Get all auxiliary statements bound attributes and the base bound
34
34
  # attributes as well
35
35
  def bound_attributes
36
- return super unless self.auxiliary_statements_values.present?
37
- bindings = self.auxiliary_statements_values.map(&:bound_attributes)
38
- (bindings + super).flatten
36
+ if Torque::PostgreSQL::AR521
37
+ visitor = ::Arel::Visitors::PostgreSQL.new(ActiveRecord::Base.connection)
38
+ visitor.accept(self.arel.ast, ::Arel::Collectors::Bind.new).value
39
+ else
40
+ return super unless self.auxiliary_statements_values.present?
41
+ bindings = self.auxiliary_statements_values.map(&:bound_attributes)
42
+ (bindings + super).flatten
43
+ end
39
44
  end
40
45
 
41
46
  private
42
47
 
43
48
  # Hook arel build to add the distinct on clause
44
- def build_arel
49
+ def build_arel(*)
45
50
  arel = super
46
51
  build_auxiliary_statements(arel)
47
52
  arel
@@ -32,8 +32,8 @@ module Torque
32
32
  private
33
33
 
34
34
  # Hook arel build to add the distinct on clause
35
- def build_arel
36
- arel = super
35
+ def build_arel(*)
36
+ arel = Torque::PostgreSQL::AR521 ? super : super()
37
37
  value = self.distinct_on_values
38
38
  arel.distinct_on(resolve_column(value)) if value.present?
39
39
  arel
@@ -57,7 +57,7 @@ module Torque
57
57
  private
58
58
 
59
59
  # Hook arel build to add any necessary table
60
- def build_arel
60
+ def build_arel(*)
61
61
  arel = super
62
62
  arel.only if self.itself_only_value === true
63
63
  build_inheritances(arel)
@@ -2,6 +2,8 @@ module Torque
2
2
  module PostgreSQL
3
3
  module SchemaDumper
4
4
 
5
+ include Adapter::ColumnDumper if Torque::PostgreSQL::AR521
6
+
5
7
  def dump(stream) # :nodoc:
6
8
  @connection.dump_mode!
7
9
  super
@@ -80,6 +82,10 @@ module Torque
80
82
 
81
83
  end
82
84
 
83
- ActiveRecord::SchemaDumper.prepend SchemaDumper
85
+ if Torque::PostgreSQL::AR521
86
+ ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper.prepend SchemaDumper
87
+ else
88
+ ActiveRecord::SchemaDumper.prepend SchemaDumper
89
+ end
84
90
  end
85
91
  end
@@ -1,5 +1,5 @@
1
1
  module Torque
2
2
  module PostgreSQL
3
- VERSION = '0.2.12'
3
+ VERSION = '0.2.13'
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: 0.2.12
4
+ version: 0.2.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2018-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '5.0'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: pg
35
29
  requirement: !ruby/object:Gem::Requirement