From 66d94ed78dced24cdd186e8bb5877cc6d43f5da8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 20 Jul 2017 14:05:03 -0500 Subject: Easier access to the variant of a blob --- lib/active_storage/blob.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/active_storage/blob.rb b/lib/active_storage/blob.rb index 1a15361747..a9d9b8771c 100644 --- a/lib/active_storage/blob.rb +++ b/lib/active_storage/blob.rb @@ -1,6 +1,7 @@ require "active_storage/service" require "active_storage/filename" require "active_storage/purge_job" +require "active_storage/variant" # Schema: id, key, filename, content_type, metadata, byte_size, checksum, created_at class ActiveStorage::Blob < ActiveRecord::Base @@ -40,6 +41,10 @@ class ActiveStorage::Blob < ActiveRecord::Base ActiveStorage::Filename.new(self[:filename]) end + def variant(variation) + ActiveStorage::Variant.new(self, variation: variation) + end + def url(expires_in: 5.minutes, disposition: :inline) service.url key, expires_in: expires_in, disposition: disposition, filename: filename end -- cgit v1.2.3