Class: DerivedImages::ManifestEntry
- Inherits:
-
Object
- Object
- DerivedImages::ManifestEntry
- Defined in:
- lib/derived_images/manifest_entry.rb
Overview
A ManifestEntry describes how to create one derived image.
Constant Summary collapse
- PROCESSORS =
{ mini_magick: ImageProcessing::MiniMagick, vips: ImageProcessing::Vips }.freeze
- COMPRESSION_OVERRIDES =
{ 'avif' => 'av1', 'heic' => 'hevc' }.freeze
Instance Attribute Summary collapse
-
#pipeline ⇒ Object
Returns the value of attribute pipeline.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#cache_key ⇒ String?
Returns a cache key for the result of the image transformation.
-
#initialize(source, target) ⇒ ManifestEntry
constructor
A new instance of ManifestEntry.
- #source_path ⇒ Object
- #source_present? ⇒ Boolean
- #target_digest ⇒ Object
- #target_path ⇒ Object
Constructor Details
#initialize(source, target) ⇒ ManifestEntry
Returns a new instance of ManifestEntry.
8 9 10 11 12 |
# File 'lib/derived_images/manifest_entry.rb', line 8 def initialize(source, target) @source = source @target = target @pipeline = default_pipeline(File.extname(target).delete_prefix('.')) end |
Instance Attribute Details
#pipeline ⇒ Object
Returns the value of attribute pipeline.
6 7 8 |
# File 'lib/derived_images/manifest_entry.rb', line 6 def pipeline @pipeline end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/derived_images/manifest_entry.rb', line 6 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/derived_images/manifest_entry.rb', line 6 def target @target end |
Class Method Details
.empty_pipeline ⇒ Object
42 43 44 |
# File 'lib/derived_images/manifest_entry.rb', line 42 def self.empty_pipeline PROCESSORS.fetch(DerivedImages.config.processor).dup end |
Instance Method Details
#==(other) ⇒ Object
14 15 16 |
# File 'lib/derived_images/manifest_entry.rb', line 14 def ==(other) source == other.source && target == other.target && == other. end |
#cache_key ⇒ String?
Returns a cache key for the result of the image transformation. It will vary if the source file’s content varies or if the operations applied to generate the target vary.
34 35 36 37 38 39 40 |
# File 'lib/derived_images/manifest_entry.rb', line 34 def cache_key return nil unless source_present? Digest::SHA256.hexdigest({ version: DerivedImages::VERSION, source: source_digest, pipeline: }.to_json) end |
#source_path ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/derived_images/manifest_entry.rb', line 18 def source_path DerivedImages.config.image_paths.each do |path| path = Pathname.new(path).join(source). return path if path.file? end nil end |
#source_present? ⇒ Boolean
53 54 55 |
# File 'lib/derived_images/manifest_entry.rb', line 53 def source_present? source_path&.file? end |
#target_digest ⇒ Object
49 50 51 |
# File 'lib/derived_images/manifest_entry.rb', line 49 def target_digest Digest::SHA256.file(target_path).hexdigest end |
#target_path ⇒ Object
26 27 28 |
# File 'lib/derived_images/manifest_entry.rb', line 26 def target_path Pathname.new(DerivedImages.config.build_path).join(target). end |