Class: Longleaf::ServiceManager
- Inherits:
-
Object
- Object
- Longleaf::ServiceManager
- Defined in:
- lib/longleaf/services/service_manager.rb
Overview
Manager which provides preservation service definitions based on their mappings
Instance Attribute Summary collapse
-
#definition_manager ⇒ Object
readonly
Returns the value of attribute definition_manager.
-
#mapping_manager ⇒ Object
readonly
Returns the value of attribute mapping_manager.
Instance Method Summary collapse
-
#applicable_for_event?(service_name, event) ⇒ Boolean
Determines if a service is applicable for a specific preservation event.
-
#initialize(definition_manager:, mapping_manager:, app_manager:) ⇒ ServiceManager
constructor
A new instance of ServiceManager.
-
#list_service_definitions(location: nil, event: nil) ⇒ Array
List definitions for services which are applicable to the given criteria.
-
#list_services(location: nil, event: nil) ⇒ Array
List the names of services which are applicable to the given criteria.
-
#perform_service(service_name, file_rec, event) ⇒ Object
Perform the specified service on the file record, in the context of the specified event.
-
#service(service_name) ⇒ Object
Return a service instance instance for provided service name.
-
#service_needed?(service_name, md_rec) ⇒ Boolean
Determine if a service should run for a particular file based on the service's definition and the file's service related metadata.
Constructor Details
#initialize(definition_manager:, mapping_manager:, app_manager:) ⇒ ServiceManager
Returns a new instance of ServiceManager
13 14 15 16 17 18 19 20 21 |
# File 'lib/longleaf/services/service_manager.rb', line 13 def initialize(definition_manager:, mapping_manager:, app_manager:) raise ArgumentError.new('Service definition manager required') if definition_manager.nil? raise ArgumentError.new('Service mappings manager required') if mapping_manager.nil? raise ArgumentError.new('Storage location manager required') if app_manager.nil? @definition_manager = definition_manager @mapping_manager = mapping_manager @app_manager = app_manager @service_class_cache = ServiceClassCache.new(app_manager) end |
Instance Attribute Details
#definition_manager ⇒ Object (readonly)
Returns the value of attribute definition_manager
7 8 9 |
# File 'lib/longleaf/services/service_manager.rb', line 7 def definition_manager @definition_manager end |
#mapping_manager ⇒ Object (readonly)
Returns the value of attribute mapping_manager
8 9 10 |
# File 'lib/longleaf/services/service_manager.rb', line 8 def mapping_manager @mapping_manager end |
Instance Method Details
#applicable_for_event?(service_name, event) ⇒ Boolean
Determines if a service is applicable for a specific preservation event
61 62 63 |
# File 'lib/longleaf/services/service_manager.rb', line 61 def applicable_for_event?(service_name, event) service(service_name).is_applicable?(event) end |
#list_service_definitions(location: nil, event: nil) ⇒ Array
List definitions for services which are applicable to the given criteria
52 53 54 55 |
# File 'lib/longleaf/services/service_manager.rb', line 52 def list_service_definitions(location: nil, event: nil) names = list_services(location: location, event: event) names.map { |name| @definition_manager.services[name] } end |
#list_services(location: nil, event: nil) ⇒ Array
List the names of services which are applicable to the given criteria
38 39 40 41 42 43 44 45 46 |
# File 'lib/longleaf/services/service_manager.rb', line 38 def list_services(location: nil, event: nil) service_names = @mapping_manager.list_services(location) if !event.nil? # Filter service names down by event service_names.select { |name| applicable_for_event?(name, event) } else service_names end end |
#perform_service(service_name, file_rec, event) ⇒ Object
Perform the specified service on the file record, in the context of the specified event
97 98 99 100 101 102 |
# File 'lib/longleaf/services/service_manager.rb', line 97 def perform_service(service_name, file_rec, event) definition = @definition_manager.services[service_name] service = @service_class_cache.service_instance(definition) service.perform(file_rec, event) end |
#service(service_name) ⇒ Object
Return a service instance instance for provided service name.
27 28 29 30 31 32 |
# File 'lib/longleaf/services/service_manager.rb', line 27 def service(service_name) raise ArgumentError.new('Service name is required') if service_name.nil? || service_name.empty? raise ArgumentError.new("No service with name #{service_name}") unless @definition_manager.services.key?(service_name) definition = @definition_manager.services[service_name] @service_class_cache.service_instance(definition) end |
#service_needed?(service_name, md_rec) ⇒ Boolean
Determine if a service should run for a particular file based on the service's definition and the file's service related metadata.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/longleaf/services/service_manager.rb', line 70 def service_needed?(service_name, md_rec) # If service not recorded for file, then it is needed present_services = md_rec.list_services return true unless present_services.include?(service_name) service_rec = md_rec.service(service_name) return true if service_rec.run_needed return true if service_rec..nil? definition = @definition_manager.services[service_name] # Check if the amount of time defined in frequency has passed since the service timestamp frequency = definition.frequency unless frequency.nil? = service_rec. now = ServiceDateHelper. return true if now > ServiceDateHelper.(, frequency) end false end |