activestorage-after_analyze_attached 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +86 -0
- data/Rakefile +3 -0
- data/lib/activestorage/after_analyze_attached/railtie.rb +6 -0
- data/lib/activestorage/after_analyze_attached/version.rb +5 -0
- data/lib/activestorage/after_analyze_attached.rb +42 -0
- data/lib/tasks/activestorage/after_analyze_attached_tasks.rake +4 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6f44aaa9dd72737da7e125e5605caf5d1d603a3e21de7f948aacd9193e0be3f1
|
4
|
+
data.tar.gz: e053f0e7f6e7e9a6b0600f04fcd528d69a1a23352ddde2e842b345573203d0a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6d238f23278a948c65877a8cc4cd772d106ec9c6010a5382e0b96183d82dffe8d1910ba4c830c69573619dc810f8ffc5a9c272b6a703141c9e391351922fa50
|
7
|
+
data.tar.gz: 28e3f54ecfa8ac16899133cd490c09c0692c9de15c413e5c329b9ae32a285c810c4d8608345b0fb491b51c954a3f430aa545db8eee07e62817328a327501f377
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Syed Fazil Basheer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Activestorage::AfterAnalyzeAttached
|
2
|
+
|
3
|
+
A Rails gem that provides a callback for when Active Storage attachments are analyzed. This is particularly useful when you need to perform actions after Active Storage has analyzed an attachment, such as updating flags, triggering background jobs, or updating the UI.
|
4
|
+
|
5
|
+
## Why use this gem?
|
6
|
+
|
7
|
+
Active Storage analyzes uploaded files asynchronously to extract metadata like image dimensions, document page count, etc. However, there's no built-in way to hook into this analysis completion event. This gem provides that missing callback, allowing you to:
|
8
|
+
|
9
|
+
- Update UI when image processing is complete
|
10
|
+
- Trigger downstream processing after file analysis
|
11
|
+
- Track progress of batch uploads
|
12
|
+
- Maintain analysis state for attachments
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
This gem adds an `after_analyze_attached` callback that you can use in your models. The callback is triggered after Active Storage analyzes an attachment.
|
17
|
+
|
18
|
+
Example:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
class Product < ApplicationRecord
|
22
|
+
has_one_attached :thumbnail
|
23
|
+
has_many_attached :gallery_images
|
24
|
+
|
25
|
+
# Update UI when thumbnail is ready
|
26
|
+
after_analyze_attached :thumbnail do
|
27
|
+
broadcast_replace_to :products,
|
28
|
+
target: dom_id(self, :thumbnail_status),
|
29
|
+
partial: "products/thumbnail_status",
|
30
|
+
locals: { product: self }
|
31
|
+
end
|
32
|
+
|
33
|
+
# Track gallery processing progress
|
34
|
+
after_analyze_attached :gallery_images do
|
35
|
+
increment!(:processed_images_count)
|
36
|
+
if processed_images_count == gallery_images.count
|
37
|
+
update!(gallery_ready: true)
|
38
|
+
GalleryProcessingJob.perform_later(self)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Document < ApplicationRecord
|
44
|
+
has_one_attached :pdf
|
45
|
+
belongs_to :organization
|
46
|
+
|
47
|
+
# Trigger OCR when PDF is analyzed
|
48
|
+
after_analyze_attached :pdf do
|
49
|
+
OcrProcessingJob.perform_later(self)
|
50
|
+
organization.members.each do |member|
|
51
|
+
DocumentMailer.ready_for_review(member, self).deliver_later
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
In these examples:
|
58
|
+
- Product thumbnails trigger UI updates via Turbo Streams when ready
|
59
|
+
- Gallery images track processing progress and trigger a job when complete
|
60
|
+
- Documents start OCR processing and notify team members when ready
|
61
|
+
|
62
|
+
## Installation
|
63
|
+
|
64
|
+
Add this line to your application's Gemfile:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
gem "activestorage-after_analyze_attached"
|
68
|
+
```
|
69
|
+
|
70
|
+
And then execute:
|
71
|
+
```bash
|
72
|
+
$ bundle
|
73
|
+
```
|
74
|
+
|
75
|
+
Or install it yourself as:
|
76
|
+
```bash
|
77
|
+
$ gem install activestorage-after_analyze_attached
|
78
|
+
```
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/frayzil/activestorage-after_analyze_attached.
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "activestorage/after_analyze_attached/version"
|
2
|
+
require "active_storage/engine"
|
3
|
+
require "rails"
|
4
|
+
|
5
|
+
module ActiveStorage::AfterAnalyzeAttached
|
6
|
+
module BlobCallbacks
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
define_callbacks :analyze
|
11
|
+
set_callback(:analyze, :after) { attachments.map(&:record).uniq.each { _1.blob_analyzed self } }
|
12
|
+
end
|
13
|
+
|
14
|
+
def analyze = run_callbacks(:analyze) { super }
|
15
|
+
end
|
16
|
+
|
17
|
+
module RecordCallbacks
|
18
|
+
extend ActiveSupport::Concern
|
19
|
+
|
20
|
+
class_methods do
|
21
|
+
def after_analyze_attached(name, &callback)
|
22
|
+
after_analyze_attached_callbacks[name.to_sym] << callback
|
23
|
+
end
|
24
|
+
|
25
|
+
def after_analyze_attached_callbacks
|
26
|
+
@after_analyze_attached_callbacks ||= Hash.new { |hash, key| hash[key] = [] }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def blob_analyzed(blob)
|
31
|
+
after_analyze_attached_callbacks(blob).each { instance_eval(&_1) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_analyze_attached_callbacks(blob)
|
35
|
+
attachment_names = ActiveStorage::Attachment.where(blob: blob).pluck(:name).map(&:to_sym)
|
36
|
+
attachment_names.flat_map { |name| self.class.after_analyze_attached_callbacks[name] }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
ActiveSupport.on_load(:active_storage_blob) { include ActiveStorage::AfterAnalyzeAttached::BlobCallbacks }
|
42
|
+
ActiveSupport.on_load(:active_record) { include ActiveStorage::AfterAnalyzeAttached::RecordCallbacks }
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activestorage-after_analyze_attached
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Syed Fazil Basheer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 8.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 8.0.1
|
27
|
+
description: This gem extends ActiveStorage to provide an after_analyze callback that
|
28
|
+
gets triggered after analyzing an attachment
|
29
|
+
email:
|
30
|
+
- fazil@fazn.co
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/activestorage/after_analyze_attached.rb
|
39
|
+
- lib/activestorage/after_analyze_attached/railtie.rb
|
40
|
+
- lib/activestorage/after_analyze_attached/version.rb
|
41
|
+
- lib/tasks/activestorage/after_analyze_attached_tasks.rake
|
42
|
+
homepage: https://github.com/frayzil/activestorage-after_analyze_attached
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
allowed_push_host: https://rubygems.org
|
47
|
+
homepage_uri: https://github.com/frayzil/activestorage-after_analyze_attached
|
48
|
+
source_code_uri: https://github.com/frayzil/activestorage-after_analyze_attached
|
49
|
+
changelog_uri: https://github.com/frayzil/activestorage-after_analyze_attached/blob/main/CHANGELOG.md
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.5.11
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Adds after_analyze callback to ActiveStorage attachments
|
69
|
+
test_files: []
|