Class: IiifPrint::PluggableDerivativeService
- Inherits:
-
Object
- Object
- IiifPrint::PluggableDerivativeService
- Defined in:
- app/services/iiif_print/pluggable_derivative_service.rb
Overview
General derivative service for IiifPrint, which is meant to wrap
and replace the stock Hyrax::FileSetDerivativeService with a proxy
that runs one or more derivative service "plugin" components.
Note: Hyrax::DerivativeService consumes this, instead of (directly)
consuming Hyrax::FileSetDerivativeService.
Unlike the "run the first valid plugin" arrangement that the
Hyrax::DerivativeService uses to run an actual derivative creation
service component, this component is:
(a) Consumed by Hyrax::DerivativeService as that first valid plugin;
(b) Wraps and runs 0..* plugins, not just the first.
This should be registered to take precedence over default by:
Hyrax::DerivativeService.services.unshift(
IiifPrint::PluggableDerivativeService
)
Modify IiifPrint::PluggableDerivativeService.plugins
to add, remove, or reorder plugin (derivative service) classes.
Instance Attribute Summary collapse
-
#file_set ⇒ Object
readonly
Returns the value of attribute file_set.
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
-
#valid_plugins ⇒ Object
readonly
Returns the value of attribute valid_plugins.
Instance Method Summary collapse
-
#initialize(file_set, plugins: plugins_for(file_set)) ⇒ PluggableDerivativeService
constructor
A new instance of PluggableDerivativeService.
-
#services(method_name) ⇒ Object
get derivative services relevant to method name and file_set context – omits plugins if particular destination exists or will soon.
-
#valid? ⇒ Boolean
this wrapper/proxy/composite is always valid, but it may compose multiple plugins, some of which may or may not be valid, so validity checks happen within as well.
Constructor Details
#initialize(file_set, plugins: plugins_for(file_set)) ⇒ PluggableDerivativeService
29 30 31 32 33 34 35 36 37 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 29 def initialize(file_set, plugins: plugins_for(file_set)) @file_set = if file_set.is_a?(Hyrax::FileMetadata) Hyrax.query_service.find_by(id: file_set.file_set_id) else file_set end @plugins = Array.wrap(plugins) @valid_plugins = plugins.map { |plugin| plugin.new(file_set) }.select(&:valid?) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **opts, &block) ⇒ Object (private)
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 65 def method_missing(method_name, *args, **opts, &block) if allowed_methods.include?(method_name) # we have an allowed method, construct services and include all valid # services for the file_set # services = plugins.map { |plugin| plugin.new(file_set) }.select(&:valid?) # run all valid services, in order: services(method_name).each do |plugin| plugin.send(method_name, *args, **opts, &block) end else super end end |
Instance Attribute Details
#file_set ⇒ Object (readonly)
Returns the value of attribute file_set.
39 40 41 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 39 def file_set @file_set end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
39 40 41 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 39 def plugins @plugins end |
#valid_plugins ⇒ Object (readonly)
Returns the value of attribute valid_plugins.
39 40 41 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 39 def valid_plugins @valid_plugins end |
Instance Method Details
#services(method_name) ⇒ Object
get derivative services relevant to method name and file_set context
-- omits plugins if particular destination exists or will soon.
51 52 53 54 55 56 57 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 51 def services(method_name) valid_plugins.select do |plugin| dest = nil dest = plugin.target_extension if plugin.respond_to?(:target_extension) !skip_destination?(method_name, dest) end end |
#valid? ⇒ Boolean
this wrapper/proxy/composite is always valid, but it may compose
multiple plugins, some of which may or may not be valid, so
validity checks happen within as well.
45 46 47 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 45 def valid? !valid_plugins.empty? end |