lockbox 0.4.5 → 0.4.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38b7a0b301adce103c1acebfa412c7a0657f687416fe237d19b02756b7019285
4
- data.tar.gz: 17a67fabef8fdab72e2821750e95caf99db70f8d35d4fc6e75033d05e93e4c4b
3
+ metadata.gz: 2fb82c6baf0c56ae7f051c8363f7cb52554ebab8180b891d4aa25caf7505cec3
4
+ data.tar.gz: 64b6bda4259cc3fddd7e5635333b0b7c4a6680c4ff2da31bba735603ea50b010
5
5
  SHA512:
6
- metadata.gz: 5fae42738060a5ab6a0f8d3dca97703e025dd1a131d474ea807fefa251d88e0ff1098c09993420f55480cb3469c26db5abfe21d93f53ddb23b920aad162bc6f6
7
- data.tar.gz: a24973afcb9f2ec6aad8a5219f23493fcc821d760e6f3fc602bf97c98e60ef05de33461f95cef188452c474bd54b7be3694c050eaea52b50548f5d08f325b56d
6
+ metadata.gz: e1953d9159c2cb1f1ec55436d925738777ea0b78afedcb32864280f7772d1d9e12a48f65c69385fd6bcdab166668049b3889f1e17e3b316c696705bcb98650dd
7
+ data.tar.gz: a3559c399a385949526137eed03b73c38baae424bed3b597c89f287222e6e18fd2c5665b2cbba6b20dad71bf680f0840ee2753a68befd3af40fdb522e45e4088
@@ -1,3 +1,7 @@
1
+ ## 0.4.6 (2020-07-02)
2
+
3
+ - Added support for `update_column` and `update_columns`
4
+
1
5
  ## 0.4.5 (2020-06-26)
2
6
 
3
7
  - Improved error message for non-string values
@@ -107,6 +107,49 @@ module Lockbox
107
107
  end
108
108
  end
109
109
  end
110
+
111
+ def update_columns(attributes)
112
+ return super unless attributes.is_a?(Hash)
113
+
114
+ # transform keys like Active Record
115
+ attributes = attributes.transform_keys do |key|
116
+ n = key.to_s
117
+ self.class.attribute_aliases[n] || n
118
+ end
119
+
120
+ lockbox_attributes = self.class.lockbox_attributes.slice(*attributes.keys.map(&:to_sym))
121
+ return super unless lockbox_attributes.any?
122
+
123
+ attributes_to_set = {}
124
+
125
+ lockbox_attributes.each do |key, lockbox_attribute|
126
+ attribute = key.to_s
127
+ # check read only
128
+ verify_readonly_attribute(attribute)
129
+
130
+ message = attributes[attribute]
131
+ attributes.delete(attribute) unless lockbox_attribute[:migrating]
132
+ encrypted_attribute = lockbox_attribute[:encrypted_attribute]
133
+ ciphertext = self.class.send("generate_#{encrypted_attribute}", message, context: self)
134
+ attributes[encrypted_attribute] = ciphertext
135
+ attributes_to_set[attribute] = message
136
+ attributes_to_set[lockbox_attribute[:attribute]] = message if lockbox_attribute[:migrating]
137
+ end
138
+
139
+ result = super(attributes)
140
+
141
+ # same logic as Active Record
142
+ # (although this happens before saving)
143
+ attributes_to_set.each do |k, v|
144
+ if respond_to?(:write_attribute_without_type_cast, true)
145
+ write_attribute_without_type_cast(k, v)
146
+ else
147
+ raw_write_attribute(k, v)
148
+ end
149
+ end
150
+
151
+ result
152
+ end
110
153
  else
111
154
  def reload
112
155
  self.class.lockbox_attributes.each do |_, v|
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler