torque-postgresql 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torque/postgresql/adapter/oid/enum.rb +3 -0
- data/lib/torque/postgresql/adapter/schema_dumper.rb +2 -2
- data/lib/torque/postgresql/associations/belongs_to_many_association.rb +7 -5
- data/lib/torque/postgresql/attributes/builder/enum.rb +5 -5
- data/lib/torque/postgresql/attributes/enum.rb +1 -1
- data/lib/torque/postgresql/attributes/enum_set.rb +1 -1
- data/lib/torque/postgresql/version.rb +1 -1
- data/spec/tests/belongs_to_many_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f5815c2fe0a3682db3ccb907a29aa171382bfa6d70ffcb58ef7e7bdbb840f65
|
4
|
+
data.tar.gz: 32ae2c431e089c2c83d6c73be202ae86e79c129f1a79a08ca596ff87ffb231f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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)
|
37
|
-
suffix = options.fetch(:suffix, nil)
|
36
|
+
prefix = options.fetch(:prefix, nil)
|
37
|
+
suffix = options.fetch(:suffix, nil)
|
38
38
|
|
39
|
-
prefix = attribute
|
40
|
-
suffix =
|
39
|
+
prefix = attribute if prefix == true
|
40
|
+
suffix = attribute if suffix == true
|
41
41
|
|
42
|
-
base =
|
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.
|
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.
|
35
|
+
defined_enums[builder.attribute.to_s] = builder.subtype
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -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.
|
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-
|
11
|
+
date: 2021-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|