Class: Hyrax::RiiifFile

Inherits:
Riiif::File
  • Object
show all
Includes:
ActiveSupport::Benchmarkable
Defined in:
lib/generators/hyrax/templates/config/initializers/riiif.rb

Overview

Adds file locking to Riiif::File

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, tempfile = nil, id:) ⇒ RiiifFile

Returns a new instance of RiiifFile.

Raises:

  • (ArgumentError)


42
43
44
45
46
# File 'lib/generators/hyrax/templates/config/initializers/riiif.rb', line 42

def initialize(input_path, tempfile = nil, id:)
  super(input_path, tempfile)
  raise(ArgumentError, "must specify id") if id.blank?
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



41
42
43
# File 'lib/generators/hyrax/templates/config/initializers/riiif.rb', line 41

def id
  @id
end

Instance Method Details

#extract(transformation, image_info = nil) ⇒ Object

Wrap extract in a read lock and benchmark it



49
50
51
52
53
54
55
# File 'lib/generators/hyrax/templates/config/initializers/riiif.rb', line 49

def extract(transformation, image_info = nil)
  Riiif::Image.file_resolver.file_locks[id].with_read_lock do
    benchmark "RiiifFile extracted #{path} with #{transformation.to_params}", level: :debug do
      super
    end
  end
end