Class: Longleaf::MetadataBuilder
- Inherits:
-
Object
- Object
- Longleaf::MetadataBuilder
- Defined in:
- lib/longleaf/specs/metadata_builder.rb
Overview
Test helper for constructing file metadata records
Instance Method Summary collapse
- #deregistered(timestamp = ServiceDateHelper::formatted_timestamp) ⇒ Object
-
#get_metadata_record ⇒ Object
The constructed metadata record.
-
#initialize(file_path: nil, registered: ServiceDateHelper::formatted_timestamp) ⇒ MetadataBuilder
constructor
A new instance of MetadataBuilder.
-
#register_to(file_rec) ⇒ Object
Add the generated metadata record to the given file record.
- #with_checksum(alg, value) ⇒ Object
- #with_physical_path(phys_path) ⇒ Object
- #with_properties(properties) ⇒ Object
- #with_service(name, timestamp: ServiceDateHelper::formatted_timestamp, run_needed: false, properties: nil, failure_timestamp: nil) ⇒ Object
-
#write_to_yaml_file(file_rec: nil) ⇒ Object
Writes the metadata record from this builder into a temporary file, or if a file record is provided, then to the expected metadata path for the record, and assigns the result as the metadata record for the file record.
Constructor Details
#initialize(file_path: nil, registered: ServiceDateHelper::formatted_timestamp) ⇒ MetadataBuilder
Returns a new instance of MetadataBuilder.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 10 def initialize(file_path: nil, registered: ServiceDateHelper::) @data = Hash.new @services = Hash.new unless file_path.nil? @last_modified = File.mtime(file_path).utc.iso8601(3) @file_size = File.size(file_path) end @registered = registered end |
Instance Method Details
#deregistered(timestamp = ServiceDateHelper::formatted_timestamp) ⇒ Object
22 23 24 25 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 22 def deregistered( = ServiceDateHelper::) @deregistered = self end |
#get_metadata_record ⇒ Object
Returns the constructed metadata record.
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 57 def MetadataRecord.new(properties: @properties, services: @services, deregistered: @deregistered, registered: @registered, checksums: @checksums, file_size: @file_size, last_modified: @last_modified, physical_path: @physical_path) end |
#register_to(file_rec) ⇒ Object
Add the generated metadata record to the given file record
69 70 71 72 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 69 def register_to(file_rec) file_rec. = self end |
#with_checksum(alg, value) ⇒ Object
27 28 29 30 31 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 27 def with_checksum(alg, value) @checksums = Hash.new unless @data.key?(MF::CHECKSUMS) @checksums[alg] = value self end |
#with_physical_path(phys_path) ⇒ Object
33 34 35 36 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 33 def with_physical_path(phys_path) @physical_path = phys_path self end |
#with_properties(properties) ⇒ Object
51 52 53 54 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 51 def with_properties(properties) @properties = properties self end |
#with_service(name, timestamp: ServiceDateHelper::formatted_timestamp, run_needed: false, properties: nil, failure_timestamp: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 38 def with_service(name, timestamp: ServiceDateHelper::, run_needed: false, properties: nil, failure_timestamp: nil) = () = () unless .nil? @services[name] = ServiceRecord.new( properties: properties.nil? ? Hash.new : nil, timestamp: , run_needed: run_needed) @services[name]. = self end |
#write_to_yaml_file(file_rec: nil) ⇒ Object
Writes the metadata record from this builder into a temporary file, or if a file record is provided, then to the expected metadata path for the record, and assigns the result as the metadata record for the file record.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/longleaf/specs/metadata_builder.rb', line 78 def write_to_yaml_file(file_rec: nil) md_path = nil if file_rec.nil? md_path = TempFile.new(['metadata', 'yml']).path else md_path = file_rec. end md_rec = MetadataSerializer::write(metadata: md_rec, file_path: md_path) file_rec. = md_rec md_path end |