Sha256: 71dd15b23b4513de6ce206a6b4fd96738292889295a0674f387e28827376e605

Contents?: true

Size: 1.25 KB

Versions: 26

Compression:

Stored size: 1.25 KB

Contents

# A definition of a derivative creation routine, this is intended to be an internal
# class, it's what's created when you call Kithe::Asset#define_derivative
class Kithe::Asset::DerivativeDefinition
  attr_reader :key, :content_type, :default_create, :proc, :storage_key
  def initialize(key:, proc:, content_type: nil, default_create: true)
    @key = key.to_sym
    @content_type = content_type
    @default_create = default_create
    @proc = proc
  end

  def call(original_file:,attacher:)
    if proc_accepts_keyword?(:attacher)
      proc.call(original_file, attacher: attacher)
    else
      proc.call(original_file)
    end
  end

  # Do content-type restrictions defined for this definition match a given asset?
  def applies_to_content_type?(original_content_type)
    return true if content_type.nil?

    return true if content_type == original_content_type

    return false if original_content_type.nil?

    return true if (content_type.kind_of?(Array) && content_type.include?(original_content_type))

    content_type == original_content_type.sub(%r{/.+\Z}, '')
  end

  private

  def proc_accepts_keyword?(kwarg)
    proc.parameters.include?([:key, kwarg]) || proc.parameters.include?([:keyreq, kwarg]) || proc.parameters.find {|a| a.first == :keyrest}
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
kithe-2.16.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.15.1 app/models/kithe/asset/derivative_definition.rb
kithe-2.15.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.14.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.13.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.12.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.11.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.10.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.9.1 app/models/kithe/asset/derivative_definition.rb
kithe-2.9.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.8.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.7.1 app/models/kithe/asset/derivative_definition.rb
kithe-2.7.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.6.1 app/models/kithe/asset/derivative_definition.rb
kithe-2.6.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.5.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.4.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.3.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.2.0 app/models/kithe/asset/derivative_definition.rb
kithe-2.1.0 app/models/kithe/asset/derivative_definition.rb