umbrellio-sequel-plugins 0.10.0.100 → 0.11.0.143
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/sequel/extensions/migration_transaction_options.rb +4 -0
- data/lib/sequel/plugins/store_accessors.rb +85 -7
- data/umbrellio-sequel-plugins.gemspec +1 -1
- 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: 4c7f90176d9dbae1bc7d18e1ad91f2755963a5c2c3dbe10fd5f8d3f96200c161
|
4
|
+
data.tar.gz: '057828ad853e3823e6e4a0da8981d531c1b880984fd74b3b3a6672a8db6e8141'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44bc22d1c7a37d0c7241c025eaa372ace531a52ca84dab3c8a191c0e4070ef0242b09e717a1a87accd6e8cc751511855a7b9bb6dd8ff26ead70ddd150002ca3c
|
7
|
+
data.tar.gz: 75691f50b458f276c5416b27d79b1ea2da4debbce8f3b4e18a58ef3e9ae0acaf3a5c525dd77f6d3c8eb4b96b78e71e8bb3761ce0f130fb6a8c1ac46a0bf9f9e0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,6 +24,10 @@ module Sequel::Plugins::StoreAccessors
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def call(_)
|
28
|
+
super.tap(&:calculate_initial_store)
|
29
|
+
end
|
30
|
+
|
27
31
|
private
|
28
32
|
|
29
33
|
def include_accessors_module(column)
|
@@ -56,19 +60,93 @@ module Sequel::Plugins::StoreAccessors
|
|
56
60
|
end
|
57
61
|
|
58
62
|
module InstanceMethods
|
59
|
-
def
|
63
|
+
def after_update
|
60
64
|
super
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
refresh_initial_store
|
66
|
+
end
|
67
|
+
|
68
|
+
def after_create
|
69
|
+
super
|
70
|
+
refresh_initial_store
|
71
|
+
end
|
72
|
+
|
73
|
+
def calculate_initial_store
|
74
|
+
@store_values_hashes || refresh_initial_store
|
75
|
+
end
|
76
|
+
|
77
|
+
def changed_columns
|
78
|
+
changed = super
|
79
|
+
return changed unless respond_to?(:store_columns)
|
80
|
+
changed = changed.dup if frozen?
|
81
|
+
store_columns.each do |col|
|
82
|
+
match = patched(col).empty? && deleted(col).empty?
|
83
|
+
if changed.include?(col)
|
84
|
+
changed.delete(col) if match
|
85
|
+
else
|
86
|
+
changed << col unless match
|
87
|
+
end
|
65
88
|
end
|
89
|
+
changed
|
66
90
|
end
|
67
91
|
|
68
|
-
|
92
|
+
private
|
93
|
+
|
94
|
+
def _update_without_checking(columns)
|
95
|
+
return super unless respond_to?(:store_columns)
|
96
|
+
|
97
|
+
mapped_columns = columns.to_h do |column, v|
|
98
|
+
next [column, v] unless store_columns.include?(column)
|
99
|
+
|
100
|
+
json = Sequel.pg_jsonb_op(
|
101
|
+
Sequel.function(:coalesce, Sequel[column], Sequel.pg_jsonb({})),
|
102
|
+
)
|
103
|
+
updated = deleted(column).inject(json) { |res, k| res.delete_path([k.to_s]) }
|
104
|
+
[column, updated.concat(patched(column))]
|
105
|
+
end
|
106
|
+
|
107
|
+
super(mapped_columns)
|
108
|
+
end
|
109
|
+
|
110
|
+
def patched(column)
|
111
|
+
initial_fields = initial_store_fields[column] || []
|
112
|
+
initial_hashes = store_values_hashes[column] || {}
|
113
|
+
current = @values[column] || {}
|
114
|
+
|
115
|
+
current.dup.delete_if do |k, v|
|
116
|
+
initial_fields.include?(k) && initial_hashes[k] == v.hash
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def deleted(column)
|
121
|
+
initial_fields = initial_store_fields[column] || []
|
122
|
+
current = @values[column] || {}
|
123
|
+
|
124
|
+
initial_fields.dup - current.keys
|
125
|
+
end
|
126
|
+
|
127
|
+
def _refresh(dataset)
|
69
128
|
super
|
129
|
+
refresh_initial_store
|
130
|
+
end
|
131
|
+
|
132
|
+
def _save_refresh
|
133
|
+
super
|
134
|
+
refresh_initial_store
|
135
|
+
end
|
136
|
+
|
137
|
+
def refresh_initial_store
|
70
138
|
return unless respond_to?(:store_columns)
|
71
|
-
|
139
|
+
store_values = @values.slice(*store_columns)
|
140
|
+
@initial_store_fields = store_values.transform_values { |v| v.to_h.keys }
|
141
|
+
@store_values_hashes = store_values.transform_values { |v| v.to_h.transform_values(&:hash) }
|
142
|
+
end
|
143
|
+
|
144
|
+
def initial_store_fields
|
145
|
+
@initial_store_fields || {}
|
146
|
+
end
|
147
|
+
|
148
|
+
def store_values_hashes
|
149
|
+
@store_values_hashes || {}
|
72
150
|
end
|
73
151
|
end
|
74
152
|
end
|
@@ -4,7 +4,7 @@ lib = File.expand_path("lib", __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
gem_version = "0.
|
7
|
+
gem_version = "0.11.0"
|
8
8
|
|
9
9
|
if ENV.fetch("PUBLISH_JOB", nil)
|
10
10
|
release_version = "#{gem_version}.#{ENV.fetch("GITHUB_RUN_NUMBER")}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-sequel-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0.143
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Umbrellio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|