umbrellio-sequel-plugins 0.4.0.81 → 0.4.0.134
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/.gitignore +0 -2
- data/.travis.yml +34 -6
- data/Gemfile.lock +117 -0
- data/README.md +107 -17
- data/lib/sequel/plugins/attr_encrypted.rb +78 -0
- data/lib/sequel/plugins/attr_encrypted/simple_crypt.rb +46 -0
- data/lib/sequel/plugins/money_accessors.rb +68 -0
- data/lib/sequel/plugins/upsert.rb +1 -1
- data/lib/sequel/timestamp_migrator_undo_extension.rb +1 -1
- data/umbrellio-sequel-plugins.gemspec +3 -2
- data/utils/database.rb +2 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61fbe7c339511660a7a6797732df54b1215d84820ba80d97f434076b329ac2af
|
4
|
+
data.tar.gz: a4802265e7bd4ffe9c21b7eaa9ba7d071bf75b81f09d6198412201882f59ede5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ee225f47d644536885adf0f63569c64e0d079abb22faca00415c663ffdaafaf27679eb63af7206dabb4accdfa87fb025e8cacece1e59feaf8ce8bb96fce9d42
|
7
|
+
data.tar.gz: 4f65c05c159e82e6999e463bd2a5c10e1c37110b43d7cec383416c9d6acd90536777740c4b936186f4deade9ece47ef2542f1de63f0ac4620755682820120577
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,25 +1,52 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
2
|
+
|
3
|
+
os: linux
|
4
|
+
dist: xenial
|
5
|
+
|
6
|
+
jobs:
|
3
7
|
fast_finish: true
|
4
8
|
include:
|
5
|
-
- rvm: 2.4
|
6
9
|
- rvm: 2.5
|
7
10
|
- rvm: 2.6
|
11
|
+
- rvm: 2.7
|
8
12
|
- rvm: ruby-head
|
9
13
|
allow_failures:
|
10
14
|
- rvm: ruby-head
|
11
|
-
|
12
|
-
cache: bundler
|
15
|
+
|
13
16
|
services:
|
14
17
|
- postgresql
|
18
|
+
|
15
19
|
addons:
|
16
|
-
postgresql:
|
17
|
-
|
20
|
+
postgresql: 12
|
21
|
+
apt:
|
22
|
+
packages:
|
23
|
+
- postgresql-12
|
24
|
+
- postgresql-client-12
|
25
|
+
- postgresql-server-dev-12
|
26
|
+
- postgresql-client-common
|
27
|
+
- postgresql-common
|
28
|
+
|
29
|
+
env:
|
30
|
+
global:
|
31
|
+
- PGPORT=5433
|
32
|
+
|
33
|
+
cache: bundler
|
34
|
+
|
35
|
+
before_install:
|
36
|
+
- gem install bundler
|
37
|
+
- sudo cp /etc/postgresql/9.6/main/pg_hba.conf /etc/postgresql/12/main/pg_hba.conf
|
38
|
+
- sudo service postgresql restart 12
|
39
|
+
- sleep 1
|
40
|
+
|
41
|
+
install: bundle install --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
|
42
|
+
|
18
43
|
before_script:
|
19
44
|
- psql -c 'create database sequel_plugins;' -U postgres
|
45
|
+
|
20
46
|
script:
|
21
47
|
- bundle exec rspec
|
22
48
|
- bundle exec rubocop
|
49
|
+
|
23
50
|
deploy:
|
24
51
|
provider: rubygems
|
25
52
|
api_key:
|
@@ -28,3 +55,4 @@ deploy:
|
|
28
55
|
on:
|
29
56
|
repo: umbrellio/umbrellio-sequel-plugins
|
30
57
|
branch: master
|
58
|
+
rvm: 2.7
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
umbrellio-sequel-plugins (0.4.0)
|
5
|
+
sequel
|
6
|
+
symbiont-ruby (>= 0.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.2.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2)
|
17
|
+
ast (2.4.0)
|
18
|
+
coderay (1.1.2)
|
19
|
+
concurrent-ruby (1.1.6)
|
20
|
+
coveralls (0.8.23)
|
21
|
+
json (>= 1.8, < 3)
|
22
|
+
simplecov (~> 0.16.1)
|
23
|
+
term-ansicolor (~> 1.3)
|
24
|
+
thor (>= 0.19.4, < 2.0)
|
25
|
+
tins (~> 1.6)
|
26
|
+
diff-lcs (1.3)
|
27
|
+
docile (1.3.2)
|
28
|
+
i18n (1.8.2)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
jaro_winkler (1.5.4)
|
31
|
+
json (2.3.0)
|
32
|
+
method_source (1.0.0)
|
33
|
+
minitest (5.14.0)
|
34
|
+
money (6.13.7)
|
35
|
+
i18n (>= 0.6.4, <= 2)
|
36
|
+
parallel (1.19.1)
|
37
|
+
parser (2.7.1.0)
|
38
|
+
ast (~> 2.4.0)
|
39
|
+
pg (1.2.3)
|
40
|
+
pry (0.13.0)
|
41
|
+
coderay (~> 1.1)
|
42
|
+
method_source (~> 1.0)
|
43
|
+
rack (2.2.2)
|
44
|
+
rainbow (3.0.0)
|
45
|
+
rake (13.0.1)
|
46
|
+
rexml (3.2.4)
|
47
|
+
rspec (3.9.0)
|
48
|
+
rspec-core (~> 3.9.0)
|
49
|
+
rspec-expectations (~> 3.9.0)
|
50
|
+
rspec-mocks (~> 3.9.0)
|
51
|
+
rspec-core (3.9.1)
|
52
|
+
rspec-support (~> 3.9.1)
|
53
|
+
rspec-expectations (3.9.1)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.9.0)
|
56
|
+
rspec-mocks (3.9.1)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.9.0)
|
59
|
+
rspec-support (3.9.2)
|
60
|
+
rubocop (0.81.0)
|
61
|
+
jaro_winkler (~> 1.5.1)
|
62
|
+
parallel (~> 1.10)
|
63
|
+
parser (>= 2.7.0.1)
|
64
|
+
rainbow (>= 2.2.2, < 4.0)
|
65
|
+
rexml
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
68
|
+
rubocop-config-umbrellio (0.81.0.78)
|
69
|
+
rubocop (= 0.81.0)
|
70
|
+
rubocop-performance (= 1.5.2)
|
71
|
+
rubocop-rails (= 2.5.0)
|
72
|
+
rubocop-rspec (= 1.38.1)
|
73
|
+
rubocop-performance (1.5.2)
|
74
|
+
rubocop (>= 0.71.0)
|
75
|
+
rubocop-rails (2.5.0)
|
76
|
+
activesupport
|
77
|
+
rack (>= 1.1)
|
78
|
+
rubocop (>= 0.72.0)
|
79
|
+
rubocop-rspec (1.38.1)
|
80
|
+
rubocop (>= 0.68.1)
|
81
|
+
ruby-progressbar (1.10.1)
|
82
|
+
sequel (5.31.0)
|
83
|
+
simplecov (0.16.1)
|
84
|
+
docile (~> 1.1)
|
85
|
+
json (>= 1.8, < 3)
|
86
|
+
simplecov-html (~> 0.10.0)
|
87
|
+
simplecov-html (0.10.2)
|
88
|
+
symbiont-ruby (0.6.0)
|
89
|
+
sync (0.5.0)
|
90
|
+
term-ansicolor (1.7.1)
|
91
|
+
tins (~> 1.0)
|
92
|
+
thor (1.0.1)
|
93
|
+
thread_safe (0.3.6)
|
94
|
+
tins (1.24.1)
|
95
|
+
sync
|
96
|
+
tzinfo (1.2.7)
|
97
|
+
thread_safe (~> 0.1)
|
98
|
+
unicode-display_width (1.7.0)
|
99
|
+
zeitwerk (2.3.0)
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
ruby
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
bundler
|
106
|
+
coveralls (>= 0.8)
|
107
|
+
money
|
108
|
+
pg
|
109
|
+
pry
|
110
|
+
rake
|
111
|
+
rspec
|
112
|
+
rubocop-config-umbrellio
|
113
|
+
simplecov
|
114
|
+
umbrellio-sequel-plugins!
|
115
|
+
|
116
|
+
BUNDLED WITH
|
117
|
+
2.1.4
|
data/README.md
CHANGED
@@ -13,28 +13,30 @@ gem 'umbrellio-sequel-plugins'
|
|
13
13
|
|
14
14
|
And then execute:
|
15
15
|
|
16
|
-
|
16
|
+
$ bundle
|
17
17
|
|
18
18
|
# Extensions
|
19
19
|
|
20
|
-
- `CurrencyRates`
|
21
|
-
- `PGTools`
|
22
|
-
- `Slave`
|
23
|
-
- `Synchronize`
|
24
|
-
- `methods_in_migrations`
|
25
|
-
- `deferrable_foreign_keys`
|
20
|
+
- [`CurrencyRates`](#CurrencyRates)
|
21
|
+
- [`PGTools`](#PGTools)
|
22
|
+
- [`Slave`](#Slave)
|
23
|
+
- [`Synchronize`](#Synchronize)
|
24
|
+
- [`methods_in_migrations`](#methods_in_migrations)
|
25
|
+
- [`deferrable_foreign_keys`](#deferrable_foreign_keys)
|
26
26
|
|
27
27
|
# Plugins
|
28
28
|
|
29
|
-
- `
|
30
|
-
- `
|
31
|
-
- `
|
32
|
-
- `
|
33
|
-
- `
|
34
|
-
- `
|
29
|
+
- [`AttrEncrypted`](#AttrEncrypted)
|
30
|
+
- [`Duplicate`](#Duplicate)
|
31
|
+
- [`GetColumnValue`](#GetColumnValue)
|
32
|
+
- [`MoneyAccessors`](#MoneyAccessors)
|
33
|
+
- [`StoreAccessors`](#StoreAccessors)
|
34
|
+
- [`Synchronize`](#Synchronize)
|
35
|
+
- [`Upsert`](#Upsert)
|
36
|
+
- [`WithLock`](#WithLock)
|
35
37
|
|
36
38
|
# Tools
|
37
|
-
- `TimestampMigratorUndoExtension`
|
39
|
+
- [`TimestampMigratorUndoExtension`](#TimestampMigratorUndoExtension)
|
38
40
|
|
39
41
|
## CurrencyRates
|
40
42
|
|
@@ -202,6 +204,40 @@ end
|
|
202
204
|
# => <Husband @attributes={id:1, wife_id: 1}>
|
203
205
|
```
|
204
206
|
|
207
|
+
## AttrEncrypted
|
208
|
+
|
209
|
+
Enable: `Sequel::Model.plugin :attr_encrypted`
|
210
|
+
|
211
|
+
Plugin for storing encrypted model attributes.
|
212
|
+
|
213
|
+
Example:
|
214
|
+
|
215
|
+
```ruby
|
216
|
+
Sequel.migration do
|
217
|
+
change do
|
218
|
+
alter_table :orders do
|
219
|
+
add_column :encrypted_first_name, :text
|
220
|
+
add_column :encrypted_last_name, :text
|
221
|
+
add_column :encrypted_secret_data, :text
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class Order < Sequel::Model
|
227
|
+
attr_encrypted :first_name, :last_name, key: Settings.private_key
|
228
|
+
attr_encrypted :secret_data, key: Settings.another_private_key, json: true
|
229
|
+
end
|
230
|
+
|
231
|
+
Order.create(first_name: "Ivan")
|
232
|
+
# => INSERT INTO "orders" ("encrypted_first_name") VALUES ('/sTi9Q==$OTpuMRq5k8R3JayQ$WjSManQGP9UaZ3C40yDjKg==')
|
233
|
+
|
234
|
+
order = Order.create(first_name: "Ivan", last_name: "Smith",
|
235
|
+
secret_data: { "some_key" => "Some Value" })
|
236
|
+
order.reload
|
237
|
+
order.first_name # => "Ivan"
|
238
|
+
order.secret_data # => { "some_key" => "Some Value" }
|
239
|
+
```
|
240
|
+
|
205
241
|
## Duplicate
|
206
242
|
|
207
243
|
Enable: `Sequel::Model.plugin :duplicate`
|
@@ -237,6 +273,60 @@ item.price # => #
|
|
237
273
|
item.get_column_value(:amount) # => 0.5e2
|
238
274
|
```
|
239
275
|
|
276
|
+
## MoneyAccessors
|
277
|
+
|
278
|
+
**Important:** requires `money` gem described below.
|
279
|
+
|
280
|
+
Plugin for using money field keys as model properties.
|
281
|
+
|
282
|
+
Enable:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
gem "money"
|
286
|
+
Sequel::Model.plugin :money_accessors
|
287
|
+
````
|
288
|
+
|
289
|
+
Examples of usage:
|
290
|
+
|
291
|
+
##### Money accessor
|
292
|
+
|
293
|
+
```ruby
|
294
|
+
class Order < Sequel::Model
|
295
|
+
money_accessor :amount, :currency
|
296
|
+
end
|
297
|
+
|
298
|
+
order = Order.create(amount: 200, currency: "EUR")
|
299
|
+
order.amount # => #<Money fractional:20000.0 currency:EUR>
|
300
|
+
order.currency # => "EUR"
|
301
|
+
|
302
|
+
order.amount = Money.new(150, "RUB")
|
303
|
+
order.amount # => #<Money fractional:150.0 currency:RUB>
|
304
|
+
```
|
305
|
+
|
306
|
+
##### Money setter
|
307
|
+
|
308
|
+
```ruby
|
309
|
+
class Order < Sequel::Model
|
310
|
+
money_setter :amount, :currency
|
311
|
+
end
|
312
|
+
|
313
|
+
order = Order.create(amount: 200, currency: "EUR")
|
314
|
+
order.amount = Money.new(150, "RUB")
|
315
|
+
order.currency # => "RUB"
|
316
|
+
```
|
317
|
+
|
318
|
+
##### Money getter
|
319
|
+
|
320
|
+
```ruby
|
321
|
+
class Order < Sequel::Model
|
322
|
+
money_getter :amount, :currency
|
323
|
+
end
|
324
|
+
|
325
|
+
order = Order.create(amount: 200, currency: "EUR")
|
326
|
+
order.amount # => #<Money fractional:20000.0 currency:EUR>
|
327
|
+
order.currency # => "EUR"
|
328
|
+
```
|
329
|
+
|
240
330
|
## StoreAccessors
|
241
331
|
|
242
332
|
Enable: `Sequel::Model.plugin :store_accessors`
|
@@ -247,7 +337,7 @@ Example:
|
|
247
337
|
|
248
338
|
```ruby
|
249
339
|
class User < Sequel::Model
|
250
|
-
|
340
|
+
store :data, :first_name
|
251
341
|
end
|
252
342
|
|
253
343
|
user = User.create(first_name: "John")
|
@@ -257,7 +347,7 @@ user.data # => {"first_name": "John"}
|
|
257
347
|
|
258
348
|
## Synchronize
|
259
349
|
|
260
|
-
**Important:** requires a `synchronize` extension described
|
350
|
+
**Important:** requires a `synchronize` extension described below.
|
261
351
|
|
262
352
|
Same as `DB#synchronize_with`
|
263
353
|
|
@@ -299,7 +389,7 @@ Example:
|
|
299
389
|
```ruby
|
300
390
|
user = User.first
|
301
391
|
user.with_lock do
|
302
|
-
|
392
|
+
user.update(name: "James")
|
303
393
|
end
|
304
394
|
```
|
305
395
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Creates encrypted attribute storing
|
4
|
+
module Sequel::Plugins::AttrEncrypted
|
5
|
+
SEPARATOR = "$"
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
# Setup attr encrypted
|
9
|
+
#
|
10
|
+
# @param attrs [Array<Symbol>] column names
|
11
|
+
# @param key [String] 32 bytes key
|
12
|
+
# @param json [Boolean] store attribute as json or not
|
13
|
+
# @example
|
14
|
+
# Sequel.migration do
|
15
|
+
# change do
|
16
|
+
# alter_table :orders do
|
17
|
+
# add_column :encrypted_first_name, :text
|
18
|
+
# add_column :encrypted_last_name, :text
|
19
|
+
# add_column :encrypted_secret_data, :text
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# class Order < Sequel::Model
|
25
|
+
# attr_encrypted :first_name, :last_name, key: Settings.private_key
|
26
|
+
# attr_encrypted :secret_data, key: Settings.another_private_key, json: true
|
27
|
+
# end
|
28
|
+
|
29
|
+
# Order.create(first_name: "Ivan")
|
30
|
+
# # => INSERT INTO "orders" ("encrypted_first_name")
|
31
|
+
# VALUES ('/sTi9Q==$OTpuMRq5k8R3JayQ$WjSManQGP9UaZ3C40yDjKg==')
|
32
|
+
#
|
33
|
+
# order = Order.create(first_name: "Ivan", last_name: "Smith",
|
34
|
+
# secret_data: { "some_key" => "Some Value" })
|
35
|
+
# order.reload
|
36
|
+
# order.first_name # => "Ivan"
|
37
|
+
# order.secret_data # => { "some_key" => "Some Value" }
|
38
|
+
def attr_encrypted(*attrs, key:, json: false)
|
39
|
+
include_encrypted_module!
|
40
|
+
attrs.each do |attr|
|
41
|
+
define_encrypted_setter(attr, key, json)
|
42
|
+
define_encrypted_getter(attr, key, json)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def define_encrypted_setter(attr, key, json)
|
49
|
+
@_attr_encrypted_module.module_eval do
|
50
|
+
define_method("#{attr}=") do |value|
|
51
|
+
instance_variable_set("@#{attr}", value)
|
52
|
+
|
53
|
+
send("encrypted_#{attr}=", SimpleCrypt.encrypt(json ? value.to_json : value, key))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def define_encrypted_getter(attr, key, json)
|
59
|
+
@_attr_encrypted_module.module_eval do
|
60
|
+
define_method(attr.to_s) do
|
61
|
+
instance_variable_get("@#{attr}") || begin
|
62
|
+
decrypted = SimpleCrypt.decrypt(send("encrypted_#{attr}"), key)
|
63
|
+
|
64
|
+
result = json && !decrypted.nil? ? JSON.parse(decrypted) : decrypted
|
65
|
+
instance_variable_set("@#{attr}", result)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def include_encrypted_module!
|
72
|
+
return if defined?(@_attr_encrypted_module)
|
73
|
+
|
74
|
+
@_attr_encrypted_module = Module.new
|
75
|
+
prepend @_attr_encrypted_module
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sequel::Plugins::AttrEncrypted::SimpleCrypt
|
4
|
+
extend self
|
5
|
+
require "base64"
|
6
|
+
|
7
|
+
SEPARATOR = "$"
|
8
|
+
|
9
|
+
def encrypt(string, key)
|
10
|
+
return unless string.is_a?(String) && !string.empty?
|
11
|
+
|
12
|
+
encryptor = new_cipher(key, &:encrypt)
|
13
|
+
iv = encryptor.random_iv
|
14
|
+
|
15
|
+
encrypted = encryptor.update(string) + encryptor.final
|
16
|
+
dump(encrypted, iv, encryptor.auth_tag)
|
17
|
+
end
|
18
|
+
|
19
|
+
def decrypt(string, key)
|
20
|
+
encrypted, iv, auth_tag = parse(string) if string.is_a?(String)
|
21
|
+
return if [encrypted, iv, auth_tag].any?(&:nil?)
|
22
|
+
|
23
|
+
decryptor = new_cipher(key, &:decrypt)
|
24
|
+
decryptor.iv = iv
|
25
|
+
decryptor.auth_tag = auth_tag
|
26
|
+
|
27
|
+
decryptor.update(encrypted) + decryptor.final
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def new_cipher(key)
|
33
|
+
result = OpenSSL::Cipher::AES256.new(:gcm)
|
34
|
+
yield(result)
|
35
|
+
result.key = key
|
36
|
+
result
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse(string)
|
40
|
+
string.split(SEPARATOR).map { |x| Base64.strict_decode64(x) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def dump(*values)
|
44
|
+
[*values].map { |x| Base64.strict_encode64(x) }.join(SEPARATOR)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "money"
|
4
|
+
|
5
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_UP
|
6
|
+
|
7
|
+
# Creates accessors for money values
|
8
|
+
module Sequel::Plugins::MoneyAccessors
|
9
|
+
MoneyClassRequired = Class.new(StandardError)
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
# Setup money accessor
|
13
|
+
#
|
14
|
+
# @param amount_column [Symbol] amount column
|
15
|
+
# @param currency_column [Symbol] currency column
|
16
|
+
# @example
|
17
|
+
# class Order < Sequel::Model
|
18
|
+
# money_accessor :amount, :currency
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# order = Order.create(amount: 200, currency: "EUR")
|
22
|
+
# order.amount # => #<Money fractional:20000.0 currency:RUB>
|
23
|
+
# order.currency # => "EUR"
|
24
|
+
def money_accessor(amount_column, currency_column)
|
25
|
+
money_getter(amount_column, currency_column)
|
26
|
+
money_setter(amount_column, currency_column)
|
27
|
+
end
|
28
|
+
|
29
|
+
def money_getter(amount_column, currency_column)
|
30
|
+
include_accessors_module!
|
31
|
+
@_money_accessors_module.module_eval do
|
32
|
+
define_method(amount_column) do
|
33
|
+
amount, currency = super(), send(currency_column)
|
34
|
+
return unless amount && currency
|
35
|
+
Money.from_amount(amount.to_d, currency)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def money_setter(amount_column, currency_column)
|
41
|
+
include_accessors_module!
|
42
|
+
@_money_accessors_module.module_eval do
|
43
|
+
define_method("#{amount_column}=") do |value|
|
44
|
+
case value
|
45
|
+
when Money
|
46
|
+
amount = value.to_d
|
47
|
+
currency = value.currency.to_s
|
48
|
+
when nil
|
49
|
+
amount = currency = nil
|
50
|
+
else
|
51
|
+
raise MoneyClassRequired, "#{amount_column} value must be either Money instance or nil"
|
52
|
+
end
|
53
|
+
|
54
|
+
super(amount)
|
55
|
+
send("#{currency_column}=", currency)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def include_accessors_module!
|
63
|
+
return if defined?(@_money_accessors_module)
|
64
|
+
@_money_accessors_module = Module.new
|
65
|
+
prepend @_money_accessors_module
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -39,7 +39,7 @@ module Sequel::Plugins::Upsert
|
|
39
39
|
# @see #upsert_dataset
|
40
40
|
def multi_upsert(rows, **options)
|
41
41
|
rows = rows.map { |row| sequel_values(row) }
|
42
|
-
upsert_dataset(options).multi_insert(rows)
|
42
|
+
upsert_dataset(**options).multi_insert(rows)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Returns formatted row values
|
@@ -21,11 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.
|
24
|
+
spec.add_runtime_dependency "sequel"
|
25
25
|
spec.add_runtime_dependency "symbiont-ruby", ">= 0.6"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler"
|
28
|
-
spec.add_development_dependency "coveralls"
|
28
|
+
spec.add_development_dependency "coveralls", ">= 0.8"
|
29
|
+
spec.add_development_dependency "money"
|
29
30
|
spec.add_development_dependency "pg"
|
30
31
|
spec.add_development_dependency "pry"
|
31
32
|
spec.add_development_dependency "rake"
|
data/utils/database.rb
CHANGED
@@ -22,8 +22,10 @@ Sequel.extension :pg_array_ops
|
|
22
22
|
Sequel.extension :pg_json_ops
|
23
23
|
Sequel.extension :pg_range_ops
|
24
24
|
|
25
|
+
Sequel::Model.plugin :attr_encrypted
|
25
26
|
Sequel::Model.plugin :duplicate
|
26
27
|
Sequel::Model.plugin :get_column_value
|
28
|
+
Sequel::Model.plugin :money_accessors
|
27
29
|
Sequel::Model.plugin :store_accessors
|
28
30
|
Sequel::Model.plugin :synchronize
|
29
31
|
Sequel::Model.plugin :upsert
|
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.0.
|
4
|
+
version: 0.4.0.134
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nulldef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -54,6 +54,20 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: money
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
@@ -164,6 +178,7 @@ files:
|
|
164
178
|
- ".travis.yml"
|
165
179
|
- CHANGELOG.md
|
166
180
|
- Gemfile
|
181
|
+
- Gemfile.lock
|
167
182
|
- LICENSE
|
168
183
|
- README.md
|
169
184
|
- Rakefile
|
@@ -175,8 +190,11 @@ files:
|
|
175
190
|
- lib/sequel/extensions/pg_tools.rb
|
176
191
|
- lib/sequel/extensions/slave.rb
|
177
192
|
- lib/sequel/extensions/synchronize.rb
|
193
|
+
- lib/sequel/plugins/attr_encrypted.rb
|
194
|
+
- lib/sequel/plugins/attr_encrypted/simple_crypt.rb
|
178
195
|
- lib/sequel/plugins/duplicate.rb
|
179
196
|
- lib/sequel/plugins/get_column_value.rb
|
197
|
+
- lib/sequel/plugins/money_accessors.rb
|
180
198
|
- lib/sequel/plugins/store_accessors.rb
|
181
199
|
- lib/sequel/plugins/synchronize.rb
|
182
200
|
- lib/sequel/plugins/upsert.rb
|
@@ -208,7 +226,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
226
|
- !ruby/object:Gem::Version
|
209
227
|
version: '0'
|
210
228
|
requirements: []
|
211
|
-
|
229
|
+
rubyforge_project:
|
230
|
+
rubygems_version: 2.7.7
|
212
231
|
signing_key:
|
213
232
|
specification_version: 4
|
214
233
|
summary: Sequel plugins
|