跳至内容 跳至搜索

Active Storage Transformers Transformer

一个 Transformer 应用一组转换到图像。

Active Storage 包含以下具体子类

方法
N
P
T

Attributes

[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 的目标图像。会产生一个包含目标图像的打开的 Tempfile。在通过给定的块产生后,关闭并取消链接输出的 tempfile。返回块的结果。

# 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 的转换图像的打开的 Tempfile。所有子类都实现了此方法。

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