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
Returns a new instance of PluggableDerivativeService.
29 30 31 32 33 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 29 def initialize(file_set, plugins: plugins_for(file_set)) @file_set = file_set @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)
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 61 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.
35 36 37 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 35 def file_set @file_set end |
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
35 36 37 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 35 def plugins @plugins end |
#valid_plugins ⇒ Object (readonly)
Returns the value of attribute valid_plugins.
35 36 37 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 35 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.
47 48 49 50 51 52 53 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 47 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.
41 42 43 |
# File 'app/services/iiif_print/pluggable_derivative_service.rb', line 41 def valid? !valid_plugins.empty? end |