File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
lib/active_storage/service Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'active_storage/service'
4+
5+ module ActiveStorage
6+ class Service ::DatabaseService < Service
7+ def upload ( key , io , checksum : nil , **)
8+ instrument :upload , key : key , checksum : checksum do
9+ ActiveStorage ::FileBlob . find_or_initialize_by ( key : key ) do
10+ it . data = io . read
11+ it . save!
12+ end
13+ end
14+ end
15+
16+ def download ( key , &block )
17+ instrument :download , key : key do
18+ ActiveStorage ::FileBlob . where ( key : key ) . pick ( :data )
19+ end
20+ end
21+
22+ def delete ( key )
23+ instrument :delete , key : key do
24+ ActiveStorage ::FileBlob . find_by ( key : key ) &.destroy
25+ end
26+ end
27+
28+ def exist? ( key )
29+ instrument :exist , key : key do |payload |
30+ payload [ :exist ] = ActiveStorage ::FileBlob . exists? ( key : key )
31+ end
32+ end
33+
34+ private
35+
36+ def service_name
37+ 'Database'
38+ end
39+ end
40+ end
You can’t perform that action at this time.
0 commit comments