跳至內容 跳至搜尋

Active Storage 分析器

這是一個分析器的抽象基底類別,用於從 Blob 提取中繼資料。參考 ActiveStorage::Analyzer::VideoAnalyzer 作為具體子類別的範例。

命名空間
方法
A
D
I
L
M
N
T

屬性

[R] blob

類別公開方法

accept?(blob)

在具體子類別中實作此方法。當給定一個分析器可以从中提取中繼資料的 Blob 時,它應該返回 true。

# File activestorage/lib/active_storage/analyzer.rb, line 13
def self.accept?(blob)
  false
end

analyze_later?()

在具體子類別中實作此方法。它將決定 Blob 分析應該在作業中完成還是在行內執行。預設情況下,分析會排入作業佇列中。

# File activestorage/lib/active_storage/analyzer.rb, line 19
def self.analyze_later?
  true
end

new(blob)

# File activestorage/lib/active_storage/analyzer.rb, line 23
def initialize(blob)
  @blob = blob
end

實體公開方法

metadata()

在具體子類別中覆寫此方法。讓它返回一個 Hash 的中繼資料。

# File activestorage/lib/active_storage/analyzer.rb, line 28
def metadata
  raise NotImplementedError
end

實體私有方法

download_blob_to_tempfile(&block)

將 Blob 下載到磁碟上的暫存檔案。產生暫存檔案。

# File activestorage/lib/active_storage/analyzer.rb, line 34
def download_blob_to_tempfile(&block) # :doc:
  blob.open tmpdir: tmpdir, &block
end

instrument(analyzer, &block)

# File activestorage/lib/active_storage/analyzer.rb, line 46
def instrument(analyzer, &block) # :doc:
  ActiveSupport::Notifications.instrument("analyze.active_storage", analyzer: analyzer, &block)
end

logger()

# File activestorage/lib/active_storage/analyzer.rb, line 38
def logger # :doc:
  ActiveStorage.logger
end

tmpdir()

# File activestorage/lib/active_storage/analyzer.rb, line 42
def tmpdir # :doc:
  Dir.tmpdir
end