Skip to content

Commit

Permalink
Add compatibility for attr_encrypted 4+ (#262)
Browse files Browse the repository at this point in the history
This method assumes that the class is using attr_encrypted for its
encryption. That gem introduced a breaking change in its most recent
major version upgrade to help with Rails 7.0 compatibility. This ensures
both versions of attr_encrypted will be compatible with data_taster and
clarifies the intention for consumers that want to use this method.

This may be compatible with ActiveRecord encryption but is untested.
  • Loading branch information
that-jill authored Apr 25, 2024
1 parent 68e1099 commit c43ed2f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/data_taster/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
PATH
remote: .
specs:
data_taster (0.2.2)
data_taster (0.3.0)
rails (>= 6.0)

GEM
Expand Down
4 changes: 4 additions & 0 deletions packages/data_taster/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [0.2.0] - 2024-04-25

- Add compatibility for encryption with newer versions of attr_encrypted

## [0.2.0] - 2023-12-24

- Rollout of basic features. See README for details.
Expand Down
2 changes: 1 addition & 1 deletion packages/data_taster/gemfiles/rails_6_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
PATH
remote: ..
specs:
data_taster (0.2.2)
data_taster (0.3.0)
rails (>= 6.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion packages/data_taster/gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
PATH
remote: ..
specs:
data_taster (0.2.2)
data_taster (0.3.0)
rails (>= 6.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion packages/data_taster/gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PATH
PATH
remote: ..
specs:
data_taster (0.2.2)
data_taster (0.3.0)
rails (>= 6.0)

GEM
Expand Down
16 changes: 15 additions & 1 deletion packages/data_taster/lib/data_taster/flavors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ def skip_sanitization
def encrypt(klass, column, value = nil)
value_to_encrypt = value || default_value_for(column)

klass.new.encrypt(column, value_to_encrypt)
klass_instance = klass.new
if klass_instance.respond_to?(:attr_encrypted_encrypt)
klass_instance.attr_encrypted_encrypt(column, value_to_encrypt)
elsif klass_instance.respond_to?(:encrypt)
klass_instance.encrypt(column, value_to_encrypt)
else
raise encryption_error_message
end
end

def encryption_error_message
[
"DataTaster only supports encryption if your model is configured with attr_encrypted.",
"Please visit https://github.com/attr-encrypted/attr_encrypted for more details on setup.",
].join(" ")
end

def default_value_for(column)
Expand Down
2 changes: 1 addition & 1 deletion packages/data_taster/lib/data_taster/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DataTaster
VERSION = "0.2.2"
VERSION = "0.3.0"
end

0 comments on commit c43ed2f

Please sign in to comment.