Class: Kithe::Asset::DerivativeDefinition
- Inherits:
-
Object
- Object
- Kithe::Asset::DerivativeDefinition
- Defined in:
- app/models/kithe/asset/derivative_definition.rb
Overview
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
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#default_create ⇒ Object
readonly
Returns the value of attribute default_create.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
-
#storage_key ⇒ Object
readonly
Returns the value of attribute storage_key.
Instance Method Summary collapse
-
#applies_to_content_type?(original_content_type) ⇒ Boolean
Do content-type restrictions defined for this definition match a given asset?.
- #call(original_file:, attacher:) ⇒ Object
-
#initialize(key:, proc:, content_type: nil, default_create: true) ⇒ DerivativeDefinition
constructor
A new instance of DerivativeDefinition.
Constructor Details
#initialize(key:, proc:, content_type: nil, default_create: true) ⇒ DerivativeDefinition
Returns a new instance of DerivativeDefinition.
5 6 7 8 9 10 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 5 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 |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
4 5 6 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 4 def content_type @content_type end |
#default_create ⇒ Object (readonly)
Returns the value of attribute default_create.
4 5 6 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 4 def default_create @default_create end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 4 def key @key end |
#proc ⇒ Object (readonly)
Returns the value of attribute proc.
4 5 6 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 4 def proc @proc end |
#storage_key ⇒ Object (readonly)
Returns the value of attribute storage_key.
4 5 6 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 4 def storage_key @storage_key end |
Instance Method Details
#applies_to_content_type?(original_content_type) ⇒ Boolean
Do content-type restrictions defined for this definition match a given asset?
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 21 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 |
#call(original_file:, attacher:) ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/models/kithe/asset/derivative_definition.rb', line 12 def call(original_file:,attacher:) if proc_accepts_keyword?(:attacher) proc.call(original_file, attacher: attacher) else proc.call(original_file) end end |