From 516ff295846a5914e1c33d6d095f47818a48aa84 Mon Sep 17 00:00:00 2001 From: Brendon Muir Date: Fri, 28 May 2021 10:36:16 +1200 Subject: [PATCH] Add load hook for ActiveStorage::VariantRecord Add a load hook called `active_storage_variant_record` (providing `ActiveStorage::VariantRecord`) to allow for overriding aspects of the `ActiveStorage::VariantRecord` class. This makes `ActiveStorage::VariantRecord` consistent with `ActiveStorage::Blob` and `ActiveStorage::Attachment` that already have load hooks. --- activestorage/CHANGELOG.md | 7 +++++++ activestorage/app/models/active_storage/variant_record.rb | 2 ++ guides/source/engines.md | 1 + 3 files changed, 10 insertions(+) diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md index 5a369383e5..5705649c35 100644 --- a/activestorage/CHANGELOG.md +++ b/activestorage/CHANGELOG.md @@ -1,3 +1,10 @@ +* Add a load hook called `active_storage_variant_record` (providing `ActiveStorage::VariantRecord`) + to allow for overriding aspects of the `ActiveStorage::VariantRecord` class. This makes + `ActiveStorage::VariantRecord` consistent with `ActiveStorage::Blob` and `ActiveStorage::Attachment` + that already have load hooks. + + *Brendon Muir* + * `ActiveStorage::PreviewError` is raised when a previewer is unable to generate a preview image. *Alex Robbin* diff --git a/activestorage/app/models/active_storage/variant_record.rb b/activestorage/app/models/active_storage/variant_record.rb index 4e552c63ec..0cc3fe3089 100644 --- a/activestorage/app/models/active_storage/variant_record.rb +++ b/activestorage/app/models/active_storage/variant_record.rb @@ -6,3 +6,5 @@ class ActiveStorage::VariantRecord < ActiveStorage::Record belongs_to :blob has_one_attached :image end + +ActiveSupport.run_load_hooks :active_storage_variant_record, ActiveStorage::VariantRecord diff --git a/guides/source/engines.md b/guides/source/engines.md index 277cb48d98..32703f6d40 100644 --- a/guides/source/engines.md +++ b/guides/source/engines.md @@ -1525,6 +1525,7 @@ These are the load hooks you can use in your own code. To hook into the initiali | `ActiveJob::TestCase` | `active_job_test_case` | | `ActiveRecord::Base` | `active_record` | | `ActiveStorage::Attachment` | `active_storage_attachment` | +| `ActiveStorage::VariantRecord` | `active_storage_variant_record` | | `ActiveStorage::Blob` | `active_storage_blob` | | `ActiveStorage::Record` | `active_storage_record` | | `ActiveSupport::TestCase` | `active_support_test_case` |