Module: LatoStorage::ApplicationHelper
- Defined in:
- app/helpers/lato_storage/application_helper.rb
Instance Method Summary collapse
- #active_storage_attachment_blob_id(attachment) ⇒ Object
- #active_storage_attachment_created_at(attachment) ⇒ Object
- #active_storage_attachment_record_id(attachment) ⇒ Object
- #active_storage_blob_byte_size(blob) ⇒ Object
- #active_storage_blob_created_at(blob) ⇒ Object
- #active_storage_blob_filename(blob) ⇒ Object
- #active_storage_variant_record_blob_id(variant_record) ⇒ Object
- #format_bytes(bytes) ⇒ Object
Instance Method Details
#active_storage_attachment_blob_id(attachment) ⇒ Object
35 36 37 38 |
# File 'app/helpers/lato_storage/application_helper.rb', line 35 def () return ' - ' if .blob.nil? link_to .blob.filename, main_app.url_for(.blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;' end |
#active_storage_attachment_created_at(attachment) ⇒ Object
27 28 29 |
# File 'app/helpers/lato_storage/application_helper.rb', line 27 def () .created_at.strftime('%Y-%m-%d %H:%M:%S') end |
#active_storage_attachment_record_id(attachment) ⇒ Object
31 32 33 |
# File 'app/helpers/lato_storage/application_helper.rb', line 31 def () "#{attachment.record_type}##{attachment.record_id}" end |
#active_storage_blob_byte_size(blob) ⇒ Object
15 16 17 |
# File 'app/helpers/lato_storage/application_helper.rb', line 15 def active_storage_blob_byte_size(blob) format_bytes blob.byte_size end |
#active_storage_blob_created_at(blob) ⇒ Object
19 20 21 |
# File 'app/helpers/lato_storage/application_helper.rb', line 19 def active_storage_blob_created_at(blob) blob.created_at.strftime('%Y-%m-%d %H:%M:%S') end |
#active_storage_blob_filename(blob) ⇒ Object
23 24 25 |
# File 'app/helpers/lato_storage/application_helper.rb', line 23 def active_storage_blob_filename(blob) link_to blob.filename, main_app.url_for(blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;' end |
#active_storage_variant_record_blob_id(variant_record) ⇒ Object
40 41 42 43 |
# File 'app/helpers/lato_storage/application_helper.rb', line 40 def active_storage_variant_record_blob_id(variant_record) return ' - ' if variant_record.blob.nil? link_to variant_record.blob.filename, main_app.url_for(variant_record.blob), target: '_blank', class: 'text-truncate d-block', style: 'max-width: 250px;' end |
#format_bytes(bytes) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/helpers/lato_storage/application_helper.rb', line 4 def format_bytes(bytes) return '0 B' if bytes.nil? || bytes == 0 units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] exponent = (Math.log(bytes) / Math.log(1024)).to_i exponent = [exponent, units.size - 1].min converted = bytes.to_f / (1024 ** exponent) "#{format('%.2f', converted)} #{units[exponent]}" end |