moab-versioning 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 749994fdd6abe9265d77a9c86595fd45790731eab77d953d2e497aa8bf294a51
4
- data.tar.gz: 46da4dba3b799cd9e03c7218863590fef18f98a15f326ab80f178424a8aaa828
3
+ metadata.gz: 0ac9a723ffc977aa08ff80ac3222a5edac9007f34516b269e53323119a129646
4
+ data.tar.gz: df5e62f7a0c6b1a328676063f08da78977465505bcafa933273f4964dab7f239
5
5
  SHA512:
6
- metadata.gz: e9c6898512516358683eb76556607942281e5a2b3f9ecb0dfe6e1e25506ae21a46f46c95b8611b3a37f6d6dd4b8b6045e54cdd0531a7e12f47a281f9218c43ab
7
- data.tar.gz: 055efae4024095b3f2dba87369fc1a2843c7f2a8d84f66277315232791f1a4ae4e1b5ffbcd6e2474665cf09c9498059f4746fa3bfcef0609381347d8368d914e
6
+ metadata.gz: 188bdd57026ac1bcdc431ce8266927414dcb4b3539ddc8b0f733240adb888bbd564f3469d6346c8948af5fcf072fb3ebde5a0cc894d65539acddfe104522e43b
7
+ data.tar.gz: c00a2aa7923f9138b34afd7d2a212dc0c9a9cd4b70a953217771fe46c4cbb2f6013d9ba4632e121a95c6238c1242fedfeba2ba8a4883775afab2558e86ad3fdd
@@ -97,16 +97,23 @@ module Moab
97
97
 
98
98
  # @api internal
99
99
  # @param signature_subset [Array<FileSignature>] The signatures used to select the entries to return
100
- # @return [Hash<String,FileSignature>] A pathname,signature hash containing a subset of the filenames in this file group
100
+ # @return [Hash<String,FileSignature>] A pathname,signature hash containing a subset of the filenames in this file
101
+ # group, e.g., {"intro-1.jpg"=>#<Moab::FileSignature>, ...}
101
102
  def path_hash_subset(signature_subset)
102
- path_hash = {}
103
- signature_subset.each do |signature|
104
- manifestation = signature_hash[signature]
105
- manifestation.instances.each do |instance|
106
- path_hash[instance.path] = signature
107
- end
103
+ # the structure of the `signature_hash` attr is documented above
104
+ signature_hash
105
+ .filter_map do |signature, manifestation|
106
+ # filters out signatures not in the provided subset
107
+ next unless signature_subset.include?(signature)
108
+
109
+ # for each instance in the manifestation, return an array of its path and the signature from the above block
110
+ manifestation.instances.map { |instance| [instance.path, signature] }
108
111
  end
109
- path_hash
112
+ # the nested map operations above return e.g.: [[["intro-1.jpg",
113
+ # #<Moab::FileSignature>],...]] which needs to be flattened one time to
114
+ # convert back into a hash
115
+ .flatten(1)
116
+ .to_h
110
117
  end
111
118
 
112
119
  # @param manifestiation_array [Array<FileManifestation>] The collection of {FileManifestation} objects
@@ -133,12 +140,11 @@ module Moab
133
140
  # @return [void] Add a single {FileSignature},{FileInstance} key/value pair to this group.
134
141
  # Data is actually stored in the {#signature_hash}
135
142
  def add_file_instance(signature, instance)
136
- if signature_hash.key?(signature)
137
- manifestation = signature_hash[signature]
138
- else
139
- manifestation = FileManifestation.new
140
- manifestation.signature = signature
141
- signature_hash[signature] = manifestation
143
+ manifestation = signature_hash[signature] || begin
144
+ FileManifestation.new.tap do |file_manifestation|
145
+ file_manifestation.signature = signature
146
+ signature_hash[signature] = file_manifestation
147
+ end
142
148
  end
143
149
  manifestation.instances << instance
144
150
  end
@@ -87,11 +87,11 @@ module Moab
87
87
  @report_datetime = Time.now
88
88
  # get a union list of all group_ids present in either inventory
89
89
  group_ids = basis_inventory.group_ids | other_inventory.group_ids
90
- group_ids.each do |group_id|
90
+ @group_differences = group_ids.map do |group_id|
91
91
  # get a pair of groups to compare, creating a empty group if not present in the inventory
92
92
  basis_group = basis_inventory.group(group_id) || FileGroup.new(group_id: group_id)
93
93
  other_group = other_inventory.group(group_id) || FileGroup.new(group_id: group_id)
94
- @group_differences << FileGroupDifference.new.compare_file_groups(basis_group, other_group)
94
+ FileGroupDifference.new.compare_file_groups(basis_group, other_group)
95
95
  end
96
96
  self
97
97
  end
@@ -45,20 +45,20 @@ module Moab
45
45
  tag 'fileSignature'
46
46
 
47
47
  # @attribute
48
- # @return [Integer] The size of the file in bytes
48
+ # @return [String] The size of the file in bytes (can be empty)
49
49
  attribute :size, Integer, on_save: proc { |n| n.to_s }
50
50
 
51
51
  # @attribute
52
- # @return [String] The MD5 checksum value of the file
53
- attribute :md5, String, on_save: proc { |n| n.nil? ? '' : n.to_s }
52
+ # @return [String] The MD5 checksum value of the file (can be empty)
53
+ attribute :md5, String, on_save: proc { |n| n.to_s }
54
54
 
55
55
  # @attribute
56
- # @return [String] The SHA1 checksum value of the file
57
- attribute :sha1, String, on_save: proc { |n| n.nil? ? '' : n.to_s }
56
+ # @return [String] The SHA1 checksum value of the file (can be empty)
57
+ attribute :sha1, String, on_save: proc { |n| n.to_s }
58
58
 
59
59
  # @attribute
60
- # @return [String] The SHA256 checksum value of the file
61
- attribute :sha256, String, on_save: proc { |n| n.nil? ? '' : n.to_s }
60
+ # @return [String] The SHA256 checksum value of the file (can be empty)
61
+ attribute :sha256, String, on_save: proc { |n| n.to_s }
62
62
 
63
63
  KNOWN_ALGOS = {
64
64
  md5: proc { Digest::MD5.new },
@@ -106,11 +106,11 @@ module Moab
106
106
 
107
107
  # @return [Hash<Symbol,String>] A hash of the checksum data
108
108
  def checksums
109
- {
110
- md5: md5,
111
- sha1: sha1,
112
- sha256: sha256
113
- }.reject { |_key, value| value.nil? || value.empty? }
109
+ @checksums ||= {}.tap do |checksum_hash|
110
+ checksum_hash[:md5] = md5 unless md5.to_s.empty?
111
+ checksum_hash[:sha1] = sha1 unless sha1.to_s.empty?
112
+ checksum_hash[:sha256] = sha256 unless sha256.to_s.empty?
113
+ end
114
114
  end
115
115
 
116
116
  # @return [Boolean] The signature contains all of the 3 desired checksums
@@ -128,7 +128,6 @@ module Moab
128
128
  # @param other [FileSignature] The other file signature being compared to this signature
129
129
  # @return [Boolean] Returns true if self and other have comparable fixity data.
130
130
  def eql?(other)
131
- return false unless other.respond_to?(:size) && other.respond_to?(:checksums)
132
131
  return false if size.to_i != other.size.to_i
133
132
 
134
133
  self_checksums = checksums
@@ -140,6 +139,8 @@ module Moab
140
139
  return false if self_checksums[key] != other_checksums[key]
141
140
  end
142
141
  true
142
+ rescue NoMethodError
143
+ false
143
144
  end
144
145
 
145
146
  # @api internal
@@ -124,7 +124,7 @@ module Stanford
124
124
  cm.to_xml
125
125
  end
126
126
 
127
- # @param content_metadata [String,Nokogiri::XML::Document] The contentMetadata as a string or XML doc
127
+ # @param content_metadata [String, Nokogiri::XML::Document] The contentMetadata as a string or XML doc
128
128
  # @return [Boolean] True if contentMetadata has essential file attributes, else raise exception
129
129
  def validate_content_metadata(content_metadata)
130
130
  result = validate_content_metadata_details(content_metadata)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moab-versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2023-01-26 00:00:00.000000000 Z
15
+ date: 2023-02-03 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: druid-tools
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  requirements: []
233
- rubygems_version: 3.2.32
233
+ rubygems_version: 3.3.7
234
234
  signing_key:
235
235
  specification_version: 4
236
236
  summary: Ruby implementation of digital object versioning toolkit used by Stanford