umbrellio-sequel-plugins 0.10.0.86 → 0.10.0.100

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a909984d827359e0f26b661e65c47568e85fc3ede84aadc5399d34ae57a76e7e
4
- data.tar.gz: 6d653809a2f7a1487c8eaba4b7e1d8ce3a6cfeca48c9a505ba858d870dc715db
3
+ metadata.gz: 461c2e1edac7a90a93262bab9b44b28455d14db79872bd6b18a488da9d5f9afc
4
+ data.tar.gz: 2ea67f3af3a257f59018861b698b3c0dc7e950f7421f0db0b75c5d08081be0c2
5
5
  SHA512:
6
- metadata.gz: da68c58784403647e587707ba0d1218618d89e4411861d1a33a87aa847688b059b70857327373010f3b6c11e7d4211f511fc4319813edfcabe30aa228846e8e4
7
- data.tar.gz: e0fee786996f3584fcb29e25312cc5a95309d060ee3c94096380e3dd1144d00362dddbb3998f5437410d81aadfe5a57c74139ff935a8388131539b39619dabc1
6
+ metadata.gz: d0f60ef1050a1c2fd371b0525c9375ca275dd9cd2d1edff184c5df229063f24cd0dba7214cb65fe1a9380040b3ad6c226e29face260c303604087fcd9ab0dd7a
7
+ data.tar.gz: e5c02e8cd6d4c4afeb48ec2b4624fcb21d906cf40481f88a8cef556decca0e7adf3ec228b36edef23f972d50af5c5817678effb6df5dd27127f8c8ac4f3579c4
@@ -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)
@@ -26,10 +26,16 @@ module Sequel::Plugins::StoreAccessors
26
26
 
27
27
  private
28
28
 
29
- def include_accessors_module
30
- return if defined?(@_store_accessors_module)
31
- @_store_accessors_module = Module.new
32
- include @_store_accessors_module
29
+ def include_accessors_module(column)
30
+ unless defined?(@_store_accessors_module)
31
+ @_store_accessors_module = Module.new
32
+ include @_store_accessors_module
33
+ end
34
+
35
+ prev_columns = @_store_accessors_module.instance_variable_get(:@_store_columns) || []
36
+ new_columns = [*prev_columns, column]
37
+ @_store_accessors_module.instance_variable_set(:@_store_columns, new_columns)
38
+ @_store_accessors_module.define_method(:store_columns) { new_columns }
33
39
  end
34
40
 
35
41
  def define_store_getter(column, field)
@@ -48,4 +54,21 @@ module Sequel::Plugins::StoreAccessors
48
54
  end
49
55
  end
50
56
  end
57
+
58
+ module InstanceMethods
59
+ def before_update
60
+ super
61
+ return unless respond_to?(:store_columns)
62
+ send(:store_columns).each do |store_column|
63
+ json = Sequel[store_column].pg_jsonb.concat(send(store_column))
64
+ send("#{store_column}=", json) if changed_columns.include?(store_column)
65
+ end
66
+ end
67
+
68
+ def after_update
69
+ super
70
+ return unless respond_to?(:store_columns)
71
+ reload unless send(:store_columns).all?(Hash)
72
+ end
73
+ end
51
74
  end
data/utils/database.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "logger"
4
4
 
5
- DB = Sequel.connect(ENV.fetch("DB_URL", "postgres://localhost/sequel_plugins"))
5
+ DB = Sequel.connect(ENV.fetch("DB_URL", "postgres:///sequel_plugins"))
6
6
  DB.logger = Logger.new("log/db.log")
7
7
 
8
8
  Sequel::Model.db = DB
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.10.0.86
4
+ version: 0.10.0.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Umbrellio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-10 00:00:00.000000000 Z
11
+ date: 2022-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubygems_version: 3.1.2
231
+ rubygems_version: 3.3.5
232
232
  signing_key:
233
233
  specification_version: 4
234
234
  summary: Sequel plugins