umbrellio-sequel-plugins 0.10.0.101 → 0.11.0.143
Sign up to get free protection for your applications and to get access to all the features.
- 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 +106 -5
- data/umbrellio-sequel-plugins.gemspec +1 -1
- data/utils/database.rb +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
@@ -16,7 +16,7 @@ module Sequel::Plugins::StoreAccessors
|
|
16
16
|
# user.first_name # => "John"
|
17
17
|
# user.data # => {"first_name": "John"}
|
18
18
|
def store(column, *fields)
|
19
|
-
include_accessors_module
|
19
|
+
include_accessors_module(column)
|
20
20
|
|
21
21
|
fields.each do |field|
|
22
22
|
define_store_getter(column, field)
|
@@ -24,12 +24,22 @@ 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
|
-
def include_accessors_module
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
def include_accessors_module(column)
|
34
|
+
unless defined?(@_store_accessors_module)
|
35
|
+
@_store_accessors_module = Module.new
|
36
|
+
include @_store_accessors_module
|
37
|
+
end
|
38
|
+
|
39
|
+
prev_columns = @_store_accessors_module.instance_variable_get(:@_store_columns) || []
|
40
|
+
new_columns = [*prev_columns, column]
|
41
|
+
@_store_accessors_module.instance_variable_set(:@_store_columns, new_columns)
|
42
|
+
@_store_accessors_module.define_method(:store_columns) { new_columns }
|
33
43
|
end
|
34
44
|
|
35
45
|
def define_store_getter(column, field)
|
@@ -48,4 +58,95 @@ module Sequel::Plugins::StoreAccessors
|
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
61
|
+
|
62
|
+
module InstanceMethods
|
63
|
+
def after_update
|
64
|
+
super
|
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
|
88
|
+
end
|
89
|
+
changed
|
90
|
+
end
|
91
|
+
|
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)
|
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
|
138
|
+
return unless respond_to?(:store_columns)
|
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 || {}
|
150
|
+
end
|
151
|
+
end
|
51
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")}"
|
data/utils/database.rb
CHANGED
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
|