File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,21 +9,30 @@ module ActiveStorage
99 end
1010
1111 def print_blob ( blob , digits : 0 )
12- size = if blob . byte_size < 1024
13- "#{ blob . byte_size } B" . rjust ( 8 )
14- else
15- "#{ blob . byte_size / 1024 } K" . rjust ( 8 )
16- end
12+ size = format_size ( blob . byte_size )
1713 date = blob . created_at . strftime ( "%Y-%m-%d %H:%M" )
1814 puts "#{ size } #{ date } #{ blob . id . to_s . rjust ( digits ) } #{ blob . filename } "
1915 end
16+
17+ def format_size ( bytes )
18+ if bytes >= 1 . gigabyte
19+ "#{ ( bytes / 1 . gigabyte . to_f ) . round ( 1 ) } G" . rjust ( 8 )
20+ elsif bytes >= 1 . megabyte
21+ "#{ ( bytes / 1 . megabyte . to_f ) . round ( 1 ) } M" . rjust ( 8 )
22+ elsif bytes >= 1 . kilobyte
23+ "#{ bytes / 1024 } K" . rjust ( 8 )
24+ else
25+ "#{ bytes } B" . rjust ( 8 )
26+ end
27+ end
2028 end
2129end
2230
2331namespace :asdb do
2432 desc "ActiveStorageDB: list attachments ordered by blob id desc"
25- task list : [ :environment ] do |_t , _args |
26- query = ActiveStorage ::Blob . order ( id : :desc ) . limit ( 100 )
33+ task :list , [ :count ] => [ :environment ] do |_t , args |
34+ count = ( args [ :count ] || 100 ) . to_i
35+ query = ActiveStorage ::Blob . order ( id : :desc ) . limit ( count )
2736 digits = query . ids . inject ( 0 ) { |ret , id |
2837 size = id . to_s . size
2938 [ size , ret ] . max
You can’t perform that action at this time.
0 commit comments