aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/active_storage/blob.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2017-07-23 11:05:20 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2017-07-23 11:05:20 -0500
commit46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea (patch)
treebc19d2f900055e39de21f62ec27e9079723cfa5f /app/models/active_storage/blob.rb
parent8f20624820ed0922b33fceb4013d3ff11015b366 (diff)
downloadrails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.gz
rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.tar.bz2
rails-46da4ee7daf1ecaa2fc47a260ccb58e119a1b5ea.zip
Switch to simpler signed_id for blob rather than full GlobalID
We don't need to lookup multiple different classes, so no need to use a globalid.
Diffstat (limited to 'app/models/active_storage/blob.rb')
-rw-r--r--app/models/active_storage/blob.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/active_storage/blob.rb b/app/models/active_storage/blob.rb
index 6bd3941cd8..7b45d3ad25 100644
--- a/app/models/active_storage/blob.rb
+++ b/app/models/active_storage/blob.rb
@@ -2,6 +2,7 @@ require "active_storage/service"
require "active_storage/filename"
require "active_storage/purge_job"
require "active_storage/variant"
+require "active_storage/variation"
# Schema: id, key, filename, content_type, metadata, byte_size, checksum, created_at
class ActiveStorage::Blob < ActiveRecord::Base
@@ -13,6 +14,10 @@ class ActiveStorage::Blob < ActiveRecord::Base
class_attribute :service
class << self
+ def find_signed(id)
+ find ActiveStorage.verifier.verify(id)
+ end
+
def build_after_upload(io:, filename:, content_type: nil, metadata: nil)
new.tap do |blob|
blob.filename = filename
@@ -33,6 +38,10 @@ class ActiveStorage::Blob < ActiveRecord::Base
end
+ def signed_id
+ ActiveStorage.verifier.generate(id)
+ end
+
def key
# We can't wait until the record is first saved to have a key for it
self[:key] ||= self.class.generate_unique_secure_token