umbrellio-sequel-plugins 0.4.0.134 → 0.4.0.145

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: 61fbe7c339511660a7a6797732df54b1215d84820ba80d97f434076b329ac2af
4
- data.tar.gz: a4802265e7bd4ffe9c21b7eaa9ba7d071bf75b81f09d6198412201882f59ede5
3
+ metadata.gz: d5d5aa7a6f7809d726257495ab1230d6273209e8c8a470df94faadbd0d3c82d3
4
+ data.tar.gz: 6cd47df601385a03216f20c79158eef81c8a85b1eeeb0ad6f0c15349d5d2f631
5
5
  SHA512:
6
- metadata.gz: 9ee225f47d644536885adf0f63569c64e0d079abb22faca00415c663ffdaafaf27679eb63af7206dabb4accdfa87fb025e8cacece1e59feaf8ce8bb96fce9d42
7
- data.tar.gz: 4f65c05c159e82e6999e463bd2a5c10e1c37110b43d7cec383416c9d6acd90536777740c4b936186f4deade9ece47ef2542f1de63f0ac4620755682820120577
6
+ metadata.gz: c78976f598b8dc8e22f3ad8f0be33d07833672615bbd60473035d3a4ef0f952053b5f16089b84e99bfc83864f313cc8f18a59b1fae895c8ac6ac1761598001b1
7
+ data.tar.gz: 502b777950b5bddbca58de8f56550da3f301f8d144e3d4e2420f45f09718592775bfe2116a5333bb2f1e321eeeb4a3d8255cc1e800797c3d4de1aac3fabf46a1
data/README.md CHANGED
@@ -21,8 +21,8 @@ $ bundle
21
21
  - [`PGTools`](#PGTools)
22
22
  - [`Slave`](#Slave)
23
23
  - [`Synchronize`](#Synchronize)
24
- - [`methods_in_migrations`](#methods_in_migrations)
25
- - [`deferrable_foreign_keys`](#deferrable_foreign_keys)
24
+ - [`Methods in Migrations`](#Methods-in-Migrations)
25
+ - [`Deferrable Foreign Keys`](#Deferrable-Foreign-Keys)
26
26
 
27
27
  # Plugins
28
28
 
@@ -225,7 +225,7 @@ end
225
225
 
226
226
  class Order < Sequel::Model
227
227
  attr_encrypted :first_name, :last_name, key: Settings.private_key
228
- attr_encrypted :secret_data, key: Settings.another_private_key, json: true
228
+ attr_encrypted :secret_data, key: Settings.another_private_key
229
229
  end
230
230
 
231
231
  Order.create(first_name: "Ivan")
@@ -3,13 +3,13 @@
3
3
  # Creates encrypted attribute storing
4
4
  module Sequel::Plugins::AttrEncrypted
5
5
  SEPARATOR = "$"
6
+ require "sequel/plugins/attr_encrypted/simple_crypt"
6
7
 
7
8
  module ClassMethods
8
9
  # Setup attr encrypted
9
10
  #
10
11
  # @param attrs [Array<Symbol>] column names
11
12
  # @param key [String] 32 bytes key
12
- # @param json [Boolean] store attribute as json or not
13
13
  # @example
14
14
  # Sequel.migration do
15
15
  # change do
@@ -23,7 +23,7 @@ module Sequel::Plugins::AttrEncrypted
23
23
  #
24
24
  # class Order < Sequel::Model
25
25
  # attr_encrypted :first_name, :last_name, key: Settings.private_key
26
- # attr_encrypted :secret_data, key: Settings.another_private_key, json: true
26
+ # attr_encrypted :secret_data, key: Settings.another_private_key
27
27
  # end
28
28
 
29
29
  # Order.create(first_name: "Ivan")
@@ -34,34 +34,36 @@ module Sequel::Plugins::AttrEncrypted
34
34
  # secret_data: { "some_key" => "Some Value" })
35
35
  # order.reload
36
36
  # order.first_name # => "Ivan"
37
+ # order.last_name # => "Smith"
37
38
  # order.secret_data # => { "some_key" => "Some Value" }
38
- def attr_encrypted(*attrs, key:, json: false)
39
+ def attr_encrypted(*attrs, key:)
39
40
  include_encrypted_module!
40
41
  attrs.each do |attr|
41
- define_encrypted_setter(attr, key, json)
42
- define_encrypted_getter(attr, key, json)
42
+ define_encrypted_setter(attr, key)
43
+ define_encrypted_getter(attr, key)
44
+ @_encrypted_attributes << attr
43
45
  end
44
46
  end
45
47
 
46
48
  private
47
49
 
48
- def define_encrypted_setter(attr, key, json)
50
+ def define_encrypted_setter(attr, key)
49
51
  @_attr_encrypted_module.module_eval do
50
52
  define_method("#{attr}=") do |value|
51
53
  instance_variable_set("@#{attr}", value)
52
54
 
53
- send("encrypted_#{attr}=", SimpleCrypt.encrypt(json ? value.to_json : value, key))
55
+ send("encrypted_#{attr}=", SimpleCrypt.encrypt(value.to_json, key))
54
56
  end
55
57
  end
56
58
  end
57
59
 
58
- def define_encrypted_getter(attr, key, json)
60
+ def define_encrypted_getter(attr, key)
59
61
  @_attr_encrypted_module.module_eval do
60
62
  define_method(attr.to_s) do
61
63
  instance_variable_get("@#{attr}") || begin
62
64
  decrypted = SimpleCrypt.decrypt(send("encrypted_#{attr}"), key)
63
65
 
64
- result = json && !decrypted.nil? ? JSON.parse(decrypted) : decrypted
66
+ result = !decrypted.nil? ? JSON.parse(decrypted) : decrypted
65
67
  instance_variable_set("@#{attr}", result)
66
68
  end
67
69
  end
@@ -71,8 +73,19 @@ module Sequel::Plugins::AttrEncrypted
71
73
  def include_encrypted_module!
72
74
  return if defined?(@_attr_encrypted_module)
73
75
 
76
+ @_encrypted_attributes ||= []
74
77
  @_attr_encrypted_module = Module.new
75
78
  prepend @_attr_encrypted_module
76
79
  end
77
80
  end
81
+
82
+ module InstanceMethods
83
+ def reload
84
+ self.class.instance_variable_get(:@_encrypted_attributes)&.each do |attr|
85
+ instance_variable_set("@#{attr}", nil)
86
+ end
87
+
88
+ super
89
+ end
90
+ end
78
91
  end
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.134
4
+ version: 0.4.0.145
5
5
  platform: ruby
6
6
  authors:
7
7
  - nulldef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel