跳到內文 跳到搜尋

Active Storage Transformers Transformer

Transformer 會對圖片套用一組轉換。

Active Storage 包含以下具體子類別

方法
N
P
T

屬性

[R] transformations

類別公共方法

new(transformations)

# File activestorage/lib/active_storage/transformers/transformer.rb, line 16
def initialize(transformations)
  @transformations = transformations
end

執行個體公共方法

transform(file, format:)

file 中的來源圖片套用轉換,產生指定 format 的目標圖片。讓出包含目標圖片的開啟暫存檔。在讓出給指定區塊後關閉和取消連結輸出暫存檔。傳回區塊的結果。

# File activestorage/lib/active_storage/transformers/transformer.rb, line 23
def transform(file, format:)
  output = process(file, format: format)

  begin
    yield output
  ensure
    output.close!
  end
end

執行個體私人方法

process(file, format:)

傳回包含以指定 format 轉換的圖片的開啟暫存檔。所有子類別都會實作這個方法。

# File activestorage/lib/active_storage/transformers/transformer.rb, line 36
def process(file, format:) # :doc:
  raise NotImplementedError
end