torque-postgresql 2.1.0 → 2.1.1

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
  SHA256:
3
- metadata.gz: cd2096d27cb0b11fd4cd2048627bf0b12dcd905d4240ea0251366f580a0afcf2
4
- data.tar.gz: c6d948dd77768feff3d85284bc838b8fb03c91233cc33ecdc8b3c22e463038c3
3
+ metadata.gz: 1f5815c2fe0a3682db3ccb907a29aa171382bfa6d70ffcb58ef7e7bdbb840f65
4
+ data.tar.gz: 32ae2c431e089c2c83d6c73be202ae86e79c129f1a79a08ca596ff87ffb231f6
5
5
  SHA512:
6
- metadata.gz: 3f61ba4bf68f2519090bb23b259cf9d8fa2c59f5a9935c867fe0dd2629eeeddd21e7a9f68a0e168550f696564d9613a4617ed6619ac4fe1f3d7660bf3fd1fc9c
7
- data.tar.gz: dbb298a6df589aa9368fb70f933b5ece9984bfc3661d667c7e42b989e2bdda6159aafbf78a303f9926f3b17dbc762473454f4646e91e976a21a0fd439a57c9f9
6
+ metadata.gz: 78c8d75e7b3534570caa48fe0a607417431813b04d842fb60b292d252d7ab0cb73ac16df488ba71242238f160ad746fe21ea162a988da0e11809c962e988b2d7
7
+ data.tar.gz: a9450b4271ddf00be01ef4fb1a45365970310887d0179c457928f8ab36d0be9378e9738befe3797380ace0cbb66181f973f4d966cd39cd3fff7eceef7afb8082
@@ -8,6 +8,9 @@ module Torque
8
8
 
9
9
  attr_reader :name, :klass, :set_klass, :enum_klass
10
10
 
11
+ # Delegate all Hash-like methods to the enum class
12
+ delegate *(Array.public_instance_methods - Object.public_methods), to: :@klass
13
+
11
14
  def self.create(row, type_map)
12
15
  name = row['typname']
13
16
  oid = row['oid'].to_i
@@ -43,13 +43,13 @@ module Torque
43
43
  inherited_tables = @connection.inherited_tables
44
44
  sorted_tables = @connection.tables.sort - @connection.views
45
45
 
46
- stream.puts " # These are the common tables managed"
46
+ stream.puts " # These are the common tables"
47
47
  (sorted_tables - inherited_tables.keys).each do |table_name|
48
48
  table(table_name, stream) unless ignored?(table_name)
49
49
  end
50
50
 
51
51
  if inherited_tables.present?
52
- stream.puts " # These are tables that has inheritance"
52
+ stream.puts " # These are tables that have inheritance"
53
53
  inherited_tables.each do |table_name, inherits|
54
54
  next if ignored?(table_name)
55
55
 
@@ -60,9 +60,11 @@ module Torque
60
60
  target
61
61
  end
62
62
 
63
- def build_changes
63
+ def build_changes(from_target = false)
64
+ return yield if defined?(@_building_changes) && @_building_changes
65
+
64
66
  @_building_changes = true
65
- yield.tap { ids_writer(ids_reader) }
67
+ yield.tap { ids_writer(from_target ? ids_reader : stale_state) }
66
68
  ensure
67
69
  @_building_changes = nil
68
70
  end
@@ -192,15 +194,15 @@ module Torque
192
194
 
193
195
  ## HAS MANY
194
196
  def replace_records(*)
195
- build_changes { super }
197
+ build_changes(true) { super }
196
198
  end
197
199
 
198
200
  def concat_records(*)
199
- build_changes { super }
201
+ build_changes(true) { super }
200
202
  end
201
203
 
202
204
  def delete_or_destroy(*)
203
- build_changes { super }
205
+ build_changes(true) { super }
204
206
  end
205
207
 
206
208
  def difference(a, b)
@@ -33,13 +33,13 @@ module Torque
33
33
  def values_methods
34
34
  return @values_methods if defined?(@values_methods)
35
35
 
36
- prefix = options.fetch(:prefix, nil).try(:<<, '_')
37
- suffix = options.fetch(:suffix, nil).try(:prepend, '_')
36
+ prefix = options.fetch(:prefix, nil)
37
+ suffix = options.fetch(:suffix, nil)
38
38
 
39
- prefix = attribute + '_' if prefix == true
40
- suffix = '_' + attribute if suffix == true
39
+ prefix = attribute if prefix == true
40
+ suffix = attribute if suffix == true
41
41
 
42
- base = "#{prefix}%s#{suffix}"
42
+ base = [prefix, '%s', suffix].compact.join('_')
43
43
 
44
44
  @values_methods = begin
45
45
  values.map do |val|
@@ -29,7 +29,7 @@ module Torque
29
29
  def include_on(klass, method_name = nil)
30
30
  method_name ||= Torque::PostgreSQL.config.enum.base_method
31
31
  Builder.include_on(klass, method_name, Builder::Enum) do |builder|
32
- defined_enums[builder.attribute.to_sym] = builder.subtype
32
+ defined_enums[builder.attribute.to_s] = builder.subtype
33
33
  end
34
34
  end
35
35
 
@@ -32,7 +32,7 @@ module Torque
32
32
  def include_on(klass, method_name = nil)
33
33
  method_name ||= Torque::PostgreSQL.config.enum.set_method
34
34
  Builder.include_on(klass, method_name, Builder::Enum, set_features: true) do |builder|
35
- defined_enums[builder.attribute.to_sym] = builder.subtype
35
+ defined_enums[builder.attribute.to_s] = builder.subtype
36
36
  end
37
37
  end
38
38
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Torque
4
4
  module PostgreSQL
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.1'
6
6
  end
7
7
  end
@@ -225,6 +225,17 @@ RSpec.describe 'BelongsToMany' do
225
225
  expect(subject.tags.size).to be_eql(0)
226
226
  end
227
227
 
228
+ it 'can clear the array' do
229
+ record = Video.create(title: 'B', tags: [initial])
230
+ expect(record.tags.size).to be_eql(1)
231
+
232
+ record.update(tag_ids: [])
233
+ record.reload
234
+
235
+ expect(record.tag_ids).to be_nil
236
+ expect(record.tags.size).to be_eql(0)
237
+ end
238
+
228
239
  it 'can have sum operations' do
229
240
  records = FactoryBot.create_list(:tag, 5)
230
241
  subject.tags.concat(records)
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: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-12 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails