class ActiveStorage::Analyzer
- Parent:
- Object
def self.accept?(blob)
false
end
Implement this method in a concrete subclass. Have it return true when given a blob from which the analyzer can extract metadata.
def self.analyze_later?
true
end
Implement this method in concrete subclasses. It will determine if blob analysis should be done in a job or performed inline. By default, analysis is enqueued in a job.
def initialize(blob)
@blob = blob
end
Override this method in a concrete subclass. Have it return a Hash
of metadata.
def download_blob_to_tempfile(&block)
blob.open tmpdir: tmpdir, &block
end
Downloads the blob to a tempfile on disk. Yields the tempfile.
def instrument(analyzer, &block)
ActiveSupport::Notifications.instrument("analyze.active_storage", analyzer: analyzer, &block)
end
def logger
ActiveStorage.logger
end
def tmpdir
Dir.tmpdir
end
© 2004–2021 David Heinemeier Hansson
Licensed under the MIT License.