Class: Longleaf::RegisterEvent
- Inherits:
-
Object
- Object
- Longleaf::RegisterEvent
- Includes:
- EventStatusTracking
- Defined in:
- lib/longleaf/events/register_event.rb
Overview
Event to register a file with longleaf
Instance Method Summary collapse
-
#initialize(file_rec:, app_manager:, force: false, digest_provider: nil) ⇒ RegisterEvent
constructor
A new instance of RegisterEvent.
-
#perform ⇒ Object
Perform a registration event on the given file.
Methods included from EventStatusTracking
#record_failure, #record_success, #return_status, #track_failure, #track_status, #track_success
Methods included from Logging
#initialize_logger, initialize_logger, logger, #logger
Constructor Details
#initialize(file_rec:, app_manager:, force: false, digest_provider: nil) ⇒ RegisterEvent
Returns a new instance of RegisterEvent.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/longleaf/events/register_event.rb', line 18 def initialize(file_rec:, app_manager:, force: false, digest_provider: nil) raise ArgumentError.new('Must provide a file_rec parameter') if file_rec.nil? raise ArgumentError.new('Parameter file_rec must be a FileRecord') \ unless file_rec.is_a?(FileRecord) raise ArgumentError.new('Must provide an ApplicationConfigManager') if app_manager.nil? raise ArgumentError.new('Parameter app_manager must be an ApplicationConfigManager') \ unless app_manager.is_a?(ApplicationConfigManager) @app_manager = app_manager @file_rec = file_rec @force = force @digest_provider = digest_provider end |
Instance Method Details
#perform ⇒ Object
Perform a registration event on the given file
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/longleaf/events/register_event.rb', line 34 def perform begin # Only need to re-register file if the force flag is provided if @file_rec. && !@force raise RegistrationError.new("Unable to register '#{@file_rec.path}', it is already registered.") end # create metadata record md_rec = MetadataRecord.new(registered: Time.now.utc.iso8601(3)) @file_rec. = md_rec # retain significant details from former record if @file_rec. retain_existing_properties end populate_file_properties if !@digest_provider.nil? checksums = @digest_provider.get_digests(@file_rec.path) md_rec.checksums.merge!(checksums) unless checksums.nil? end # persist the metadata @app_manager.md_manager.persist(@file_rec) record_success(EventNames::REGISTER, @file_rec.path) rescue RegistrationError => err record_failure(EventNames::REGISTER, @file_rec.path, err.) rescue InvalidStoragePathError => err record_failure(EventNames::REGISTER, @file_rec.path, err.) end return_status end |