moab-versioning 3.0.0 → 4.0.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
  SHA1:
3
- metadata.gz: 0cbc9f88a390634b7acc77dacc9839b89849835b
4
- data.tar.gz: 815ef9d707ebeea48a711ca985a6a7a28e82c784
3
+ metadata.gz: 3e5f606dfba2cd8e6b58c044835b380fbfe6fbd2
4
+ data.tar.gz: 53ac0623d30970defef6303eb5a60dbc08251b72
5
5
  SHA512:
6
- metadata.gz: c002027ea5b5047ae4024e9f914e8949a652bc067f49e3cff3dee02b8b602f1111c5086a951af9ad2d8c82935da9aa88bbc72eaf75c68d598e0d9bb404845540
7
- data.tar.gz: 19a800a7e7b20acb2e14726ce5127d96f30ae05ed3eced4d6a50ae6c7b016298163caa2beb6bcbdab07a8a4868cae7b5fa21e6458b1ad03a7236751d030a8d43
6
+ metadata.gz: 330703dff850a3fd21e9a70839df565811b668cbdc228cf59ceafc8633b0cb703893298a054936fc5e87f2d66fc76e2599baa4dcb6c7eb16b7d1438e9bdcb738
7
+ data.tar.gz: 4f55f879bd0d6dd5e0ff3ee0f8ce7db04566006cf7af5ddd0a252c521e6c79a7f0857808756f09bb0a05907eece777e0ffd8d171f463467d92f5a0705a7f8f9f
@@ -11,12 +11,13 @@ module Moab
11
11
  EXPECTED_DATA_SUB_DIRS = [CONTENT_DIR, METADATA_DIR].freeze
12
12
  IMPLICIT_DIRS = ['.', '..', '.keep'].freeze # unlike Find.find, Dir.entries returns the current/parent dirs
13
13
  DATA_DIR = "data".freeze
14
- EXPECTED_VERSION_SUB_DIRS = [DATA_DIR, "manifests"].freeze
15
- MANIFEST_INVENTORY_PATH = 'manifests/manifestInventory.xml'.freeze
16
- SIGNATURE_CATALOG_PATH = 'manifests/signatureCatalog.xml'.freeze
14
+ MANIFESTS_DIR = 'manifests'.freeze
15
+ EXPECTED_VERSION_SUB_DIRS = [DATA_DIR, MANIFESTS_DIR].freeze
16
+ MANIFEST_INVENTORY_PATH = File.join(MANIFESTS_DIR, "manifestInventory.xml").freeze
17
+ SIGNATURE_CATALOG_PATH = File.join(MANIFESTS_DIR, "signatureCatalog.xml").freeze
17
18
 
18
19
  # error codes
19
- INCORRECT_DIR = 0
20
+ INCORRECT_DIR_CONTENTS = 0
20
21
  MISSING_DIR = 1
21
22
  EXTRA_CHILD_DETECTED = 2
22
23
  VERSION_DIR_BAD_FORMAT = 3
@@ -41,47 +42,45 @@ module Moab
41
42
  errors = []
42
43
  errors.concat check_correctly_named_version_dirs
43
44
  errors.concat check_sequential_version_dirs if errors.empty?
44
- errors.concat check_correctly_formed_moabs if errors.empty?
45
+ errors.concat check_correctly_formed_moab if errors.empty?
45
46
  errors
46
47
  end
47
48
 
48
49
  def self.error_code_to_messages
49
50
  @error_code_to_messages ||=
50
51
  {
51
- INCORRECT_DIR => "Incorrect items in path",
52
+ INCORRECT_DIR_CONTENTS => "Incorrect items under %{addl} directory",
52
53
  MISSING_DIR => "Missing directory: %{addl}",
53
54
  EXTRA_CHILD_DETECTED => "Unexpected item in path: %{addl}",
54
- VERSION_DIR_BAD_FORMAT => "Version directory name not in 'v00xx' format",
55
- FILES_IN_VERSION_DIR => "Top level should contain only sequential version directories. Also contains files: %{addl}",
56
- NO_SIGNATURE_CATALOG => "Version: %{addl} Missing signatureCatalog.xml",
57
- NO_MANIFEST_INVENTORY => "Version: %{addl} Missing manifestInventory.xml",
58
- NO_FILES_IN_MANIFEST_DIR => "Version: %{addl} No files present in manifest dir",
59
- METADATA_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the metadata directory",
55
+ VERSION_DIR_BAD_FORMAT => "Version directory name not in 'v00xx' format: %{addl}",
56
+ FILES_IN_VERSION_DIR => "Version directory %{addl} should not contain files; only the manifests and data directories",
57
+ NO_SIGNATURE_CATALOG => "Version %{addl}: Missing signatureCatalog.xml",
58
+ NO_MANIFEST_INVENTORY => "Version %{addl}: Missing manifestInventory.xml",
59
+ NO_FILES_IN_MANIFEST_DIR => "Version %{addl}: No files present in manifest dir",
60
+ METADATA_SUB_DIRS_DETECTED => "Version %{addl}: metadata directory should only contain files, not directories",
60
61
  VERSIONS_NOT_IN_ORDER => "Should contain only sequential version directories. Current directories: %{addl}",
61
- NO_FILES_IN_METADATA_DIR => "Version: %{addl} No files present in metadata dir",
62
- NO_FILES_IN_CONTENT_DIR => "Version: %{addl} No files present in content dir",
63
- CONTENT_SUB_DIRS_DETECTED => "Should only contain files, but directories were present in the content directory"
62
+ NO_FILES_IN_METADATA_DIR => "Version %{addl}: No files present in metadata dir",
63
+ NO_FILES_IN_CONTENT_DIR => "Version %{addl}: No files present in content dir",
64
+ CONTENT_SUB_DIRS_DETECTED => "Version %{addl}: content directory should only contain files, not directories"
64
65
  }.freeze
65
66
  end
66
67
 
67
- # TODO: Figure out which methods should be public
68
-
69
68
  private
70
69
 
71
70
  def version_directories
72
- @vdirs ||= sub_dirs(storage_obj_path)
71
+ @vdirs ||= directory_entries(storage_obj_path)
73
72
  end
74
73
 
75
74
  def check_correctly_named_version_dirs
76
75
  errors = []
77
76
  errors << result_hash(MISSING_DIR, 'no versions exist') unless version_directories.count > 0
78
77
  version_directories.each do |version_dir|
79
- errors << result_hash(VERSION_DIR_BAD_FORMAT) unless version_dir =~ /^[v]\d{4}$/
78
+ errors << result_hash(VERSION_DIR_BAD_FORMAT, version_dir) unless version_dir =~ /^[v]\d{4}$/
80
79
  end
81
80
  errors
82
81
  end
83
82
 
84
- # This method will be called only if the version directories are correctly named
83
+ # call only if the version directories are "correctly named" vdddd
85
84
  def check_sequential_version_dirs
86
85
  errors = []
87
86
  version_directories.each_with_index do |dir_name, index|
@@ -91,28 +90,27 @@ module Moab
91
90
  break
92
91
  end
93
92
  end
94
-
95
93
  errors
96
94
  end
97
95
 
98
- def check_correctly_formed_moabs
96
+ def check_correctly_formed_moab
99
97
  errors = []
100
98
  version_directories.each do |version_dir|
101
- version_path = "#{storage_obj_path}/#{version_dir}"
102
- version_sub_dirs = sub_dirs(version_path)
99
+ version_path = File.join(storage_obj_path, version_dir)
103
100
  version_error_count = errors.size
104
- errors.concat check_version_sub_dirs(version_sub_dirs, version_dir)
101
+ errors.concat check_version_sub_dirs(version_path, version_dir)
105
102
  errors.concat check_required_manifest_files(version_path, version_dir) if version_error_count == errors.size
106
103
  errors.concat check_data_directory(version_path, version_dir) if version_error_count == errors.size
107
104
  end
108
105
  errors
109
106
  end
110
107
 
111
- def check_version_sub_dirs(version_sub_dirs, version)
108
+ def check_version_sub_dirs(version_path, version)
112
109
  errors = []
110
+ version_sub_dirs = directory_entries(version_path)
113
111
  version_sub_dir_count = version_sub_dirs.size
114
112
  if version_sub_dir_count == EXPECTED_VERSION_SUB_DIRS.size
115
- errors.concat expected_dirs(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
113
+ errors.concat expected_version_sub_dirs(version_path, version)
116
114
  elsif version_sub_dir_count > EXPECTED_VERSION_SUB_DIRS.size
117
115
  errors.concat found_unexpected(version_sub_dirs, version, EXPECTED_VERSION_SUB_DIRS)
118
116
  elsif version_sub_dir_count < EXPECTED_VERSION_SUB_DIRS.size
@@ -123,8 +121,8 @@ module Moab
123
121
 
124
122
  def check_data_directory(version_path, version)
125
123
  errors = []
126
- data_dir_path = "#{version_path}/#{DATA_DIR}"
127
- data_sub_dirs = sub_dirs(data_dir_path)
124
+ data_dir_path = File.join(version_path, DATA_DIR)
125
+ data_sub_dirs = directory_entries(data_dir_path)
128
126
  errors.concat check_data_sub_dirs(version, data_sub_dirs)
129
127
  errors.concat check_metadata_dir_files_only(version_path) if errors.empty?
130
128
  errors.concat check_optional_content_dir_files_only(version_path) if data_sub_dirs.include?('content') && errors.empty?
@@ -145,12 +143,9 @@ module Moab
145
143
 
146
144
  def check_optional_content_dir_files_only(version_path)
147
145
  errors = []
148
- dir_list = []
149
- content_dir_path = "#{version_path}/#{DATA_DIR}/#{CONTENT_DIR}"
150
- content_sub_dirs = sub_dirs(content_dir_path)
151
- content_sub_dirs.each { |item| dir_list << File.directory?("#{content_dir_path}/#{item}") }
152
- errors << result_hash(NO_FILES_IN_CONTENT_DIR) if directory_entries(content_dir_path).empty?
153
- errors << result_hash(CONTENT_SUB_DIRS_DETECTED) if dir_list.include?(true)
146
+ content_dir_path = File.join(version_path, DATA_DIR, CONTENT_DIR)
147
+ errors << result_hash(NO_FILES_IN_CONTENT_DIR, basename(version_path)) if directory_entries(content_dir_path).empty?
148
+ errors << result_hash(CONTENT_SUB_DIRS_DETECTED, basename(version_path)) if contains_sub_dir?(content_dir_path)
154
149
  errors
155
150
  end
156
151
 
@@ -160,12 +155,9 @@ module Moab
160
155
 
161
156
  def check_metadata_dir_files_only(version_path)
162
157
  errors = []
163
- dir_list = []
164
- metadata_dir_path = "#{version_path}/#{DATA_DIR}/#{METADATA_DIR}"
165
- metadata_sub_dirs = sub_dirs(metadata_dir_path)
166
- metadata_sub_dirs.each { |item| dir_list << File.directory?("#{metadata_dir_path}/#{item}") }
167
- errors << result_hash(NO_FILES_IN_METADATA_DIR) if directory_entries(metadata_dir_path).empty?
168
- errors << result_hash(METADATA_SUB_DIRS_DETECTED) if dir_list.include?(true)
158
+ metadata_dir_path = File.join(version_path, DATA_DIR, METADATA_DIR)
159
+ errors << result_hash(NO_FILES_IN_METADATA_DIR, basename(version_path)) if directory_entries(metadata_dir_path).empty?
160
+ errors << result_hash(METADATA_SUB_DIRS_DETECTED, basename(version_path)) if contains_sub_dir?(metadata_dir_path)
169
161
  errors
170
162
  end
171
163
 
@@ -182,10 +174,6 @@ module Moab
182
174
  end
183
175
  end
184
176
 
185
- def sub_dirs(path)
186
- directory_entries(path)
187
- end
188
-
189
177
  def found_unexpected(array, version, required_sub_dirs)
190
178
  errors = []
191
179
  unexpected = (array - required_sub_dirs)
@@ -202,12 +190,28 @@ module Moab
202
190
  errors
203
191
  end
204
192
 
205
- def expected_dirs(array, _version, required_sub_dirs)
193
+ def expected_version_sub_dirs(version_path, version)
206
194
  errors = []
207
- errors << result_hash(INCORRECT_DIR) unless array == required_sub_dirs
195
+ version_sub_dirs = directory_entries(version_path)
196
+ errors << result_hash(INCORRECT_DIR_CONTENTS, version) unless version_sub_dirs == EXPECTED_VERSION_SUB_DIRS
197
+ if contains_file?(version_path)
198
+ errors << result_hash(FILES_IN_VERSION_DIR, version)
199
+ end
208
200
  errors
209
201
  end
210
202
 
203
+ def contains_sub_dir?(path)
204
+ directory_entries(path).detect { |entry| File.directory?(File.join(path, entry)) }
205
+ end
206
+
207
+ def contains_file?(path)
208
+ directory_entries(path).detect { |entry| File.file?(File.join(path, entry)) }
209
+ end
210
+
211
+ def basename(path)
212
+ path.split(File::SEPARATOR)[-1]
213
+ end
214
+
211
215
  def result_hash(response_code, addl=nil)
212
216
  { response_code => error_code_msg(response_code, addl) }
213
217
  end
@@ -218,23 +222,22 @@ module Moab
218
222
 
219
223
  def check_required_manifest_files(dir, version)
220
224
  errors = []
221
- has_manifest_inventory = File.exist?("#{dir}/#{MANIFEST_INVENTORY_PATH}")
222
- has_signature_catalog = File.exist?("#{dir}/#{SIGNATURE_CATALOG_PATH}")
223
- result = if has_manifest_inventory && has_signature_catalog
224
- nil
225
- elsif has_manifest_inventory && !has_signature_catalog
226
- result_hash(NO_SIGNATURE_CATALOG, version)
227
- elsif !has_manifest_inventory && has_signature_catalog
228
- result_hash(NO_MANIFEST_INVENTORY, version)
229
- else
230
- result_hash(NO_FILES_IN_MANIFEST_DIR, version)
231
- end
232
- errors << result if result
225
+ unless contains_file?(File.join(dir, MANIFESTS_DIR))
226
+ errors << result_hash(NO_FILES_IN_MANIFEST_DIR, version)
227
+ return errors
228
+ end
229
+
230
+ unless File.exist?(File.join(dir, MANIFEST_INVENTORY_PATH))
231
+ errors << result_hash(NO_MANIFEST_INVENTORY, version)
232
+ end
233
+ unless File.exist?(File.join(dir, SIGNATURE_CATALOG_PATH))
234
+ errors << result_hash(NO_SIGNATURE_CATALOG, version)
235
+ end
233
236
  errors
234
237
  end
235
238
 
236
239
  def latest_manifest_inventory
237
- "#{storage_obj_path}/#{version_directories.last}/#{MANIFEST_INVENTORY_PATH}"
240
+ File.join(storage_obj_path, version_directories.last, MANIFEST_INVENTORY_PATH)
238
241
  end
239
242
 
240
243
  def object_id_from_manifest_inventory
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: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Weber
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-11-17 00:00:00.000000000 Z
14
+ date: 2017-11-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: confstruct