Skip to content

Commit

Permalink
Dropped support for Active Record < 7, Mongoid < 8, and Ruby < 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Oct 23, 2024
1 parent cbcba7b commit 3fc1934
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 293 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,12 @@ jobs:
gemfile: gemfiles/rails71.gemfile
- ruby: 3.1
gemfile: gemfiles/rails70.gemfile
- ruby: "3.0"
gemfile: gemfiles/rails61.gemfile
- ruby: 2.7
gemfile: gemfiles/rails60.gemfile
- ruby: 2.6
gemfile: gemfiles/rails52.gemfile
- ruby: 3.3
gemfile: gemfiles/mongoid9.gemfile
mongodb: true
- ruby: 3.1
gemfile: gemfiles/mongoid8.gemfile
mongodb: true
- ruby: 2.7
gemfile: gemfiles/mongoid7.gemfile
mongodb: true
- ruby: 2.6
gemfile: gemfiles/mongoid6.gemfile
mongodb: true
env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
steps:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.0 (unreleased)

- Dropped support for Active Record < 7 and Ruby < 3.1
- Dropped support for Mongoid < 8

## 1.4.1 (2024-09-09)

- Fixed error message for previews for Active Storage 7.1.4
Expand Down
14 changes: 0 additions & 14 deletions gemfiles/mongoid6.gemfile

This file was deleted.

14 changes: 0 additions & 14 deletions gemfiles/mongoid7.gemfile

This file was deleted.

15 changes: 0 additions & 15 deletions gemfiles/rails52.gemfile

This file was deleted.

15 changes: 0 additions & 15 deletions gemfiles/rails60.gemfile

This file was deleted.

15 changes: 0 additions & 15 deletions gemfiles/rails61.gemfile

This file was deleted.

6 changes: 1 addition & 5 deletions lib/generators/lockbox/audits_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def data_type
# use connection_config instead of connection.adapter
# so database connection isn't needed
def adapter
if ActiveRecord::VERSION::STRING.to_f >= 6.1
ActiveRecord::Base.connection_db_config.adapter.to_s
else
ActiveRecord::Base.connection_config[:adapter].to_s
end
ActiveRecord::Base.connection_db_config.adapter.to_s
end
end
end
Expand Down
16 changes: 13 additions & 3 deletions lib/lockbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def self.encrypts_action_text_body(**options)
if defined?(ActiveSupport.on_load)
ActiveSupport.on_load(:active_record) do
ar_version = ActiveRecord::VERSION::STRING.to_f
if ar_version < 5.2
if ar_version >= 5
if ar_version < 7
if ar_version >= 5.2
raise Lockbox::Error, "Active Record #{ActiveRecord::VERSION::STRING} requires Lockbox < 2"
elsif ar_version >= 5
raise Lockbox::Error, "Active Record #{ActiveRecord::VERSION::STRING} requires Lockbox < 0.7"
else
raise Lockbox::Error, "Active Record #{ActiveRecord::VERSION::STRING} not supported"
Expand All @@ -109,11 +111,19 @@ def self.encrypts_action_text_body(**options)

extend Lockbox::Model
extend Lockbox::Model::Attached
singleton_class.alias_method(:encrypts, :lockbox_encrypts) if ActiveRecord::VERSION::MAJOR < 7
ActiveRecord::Relation.prepend Lockbox::Calculations
end

ActiveSupport.on_load(:mongoid) do
mongoid_version = Mongoid::VERSION.to_i
if mongoid_version < 8
if mongoid_version >= 6
raise Lockbox::Error, "Mongoid #{Mongoid::VERSION} requires Lockbox < 2"
else
raise Lockbox::Error, "Mongoid #{Mongoid::VERSION} not supported"
end
end

Mongoid::Document::ClassMethods.include(Lockbox::Model)
Mongoid::Document::ClassMethods.alias_method(:encrypts, :lockbox_encrypts)
end
Expand Down
58 changes: 18 additions & 40 deletions lib/lockbox/active_storage_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ def encrypt_attachable(attachable)
end

module AttachedOne
if ActiveStorage::VERSION::MAJOR < 6
def attach(attachable)
attachable = encrypt_attachable(attachable) if encrypted?
super(attachable)
end
end

def rotate_encryption!
raise "Not encrypted" unless encrypted?

Expand All @@ -51,19 +44,6 @@ def rotate_encryption!
end

module AttachedMany
if ActiveStorage::VERSION::MAJOR < 6
def attach(*attachables)
if encrypted?
attachables =
attachables.flatten.collect do |attachable|
encrypt_attachable(attachable)
end
end

super(attachables)
end
end

def rotate_encryption!
raise "Not encrypted" unless encrypted?

Expand Down Expand Up @@ -131,27 +111,25 @@ def transform_variants_later
end
end

if ActiveStorage::VERSION::MAJOR >= 6
def open(**options)
blob.open(**options) do |file|
options = Utils.encrypted_options(record, name)
# only trust the metadata when migrating
# as earlier versions of Lockbox won't have it
# and it's not a good practice to trust modifiable data
encrypted = options && (!options[:migrating] || blob.metadata["encrypted"])
if encrypted
result = Utils.decrypt_result(record, name, options, file.read)
file.rewind
# truncate may not be available on all platforms
# according to the Ruby docs
# may need to create a new temp file instead
file.truncate(0)
file.write(result)
file.rewind
end

yield file
def open(**options)
blob.open(**options) do |file|
options = Utils.encrypted_options(record, name)
# only trust the metadata when migrating
# as earlier versions of Lockbox won't have it
# and it's not a good practice to trust modifiable data
encrypted = options && (!options[:migrating] || blob.metadata["encrypted"])
if encrypted
result = Utils.decrypt_result(record, name, options, file.read)
file.rewind
# truncate may not be available on all platforms
# according to the Ruby docs
# may need to create a new temp file instead
file.truncate(0)
file.write(result)
file.rewind
end

yield file
end
end
end
Expand Down
Loading

0 comments on commit 3fc1934

Please sign in to comment.