assembly-objectfile 1.10.2 → 1.10.3
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 +4 -4
- data/.rubocop_todo.yml +7 -7
- data/lib/assembly-objectfile.rb +8 -0
- data/lib/assembly-objectfile/object_fileable.rb +14 -4
- data/lib/assembly-objectfile/version.rb +1 -1
- data/spec/object_file_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/test_data/input/test.json +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0060fb5fbd2271cc712b63d2d1ff8752c7ab11346f7ee0a43f41fcc48288d805
|
4
|
+
data.tar.gz: 1759dd3e2e5c8ab86333957f30b27468296b53b0f4c7e1607f08e09b4f77da9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fa4a4f685bfd3f1c95284b07f8531b1bcdb6330d54b578ad5fefb7e394dd04431bb666930902204b06b44fedeefb9dca0fa9e69939775d27b40df2d41d434a
|
7
|
+
data.tar.gz: ccd72959056a26a186c32247100a86ffc7596ce3ef960800ada4f7c6677da13548b4e54dd5614c015555676d25264e5850d809fab3da7a968312af071654a984
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2021-
|
3
|
+
# on 2021-04-26 18:43:37 UTC using RuboCop version 1.11.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -14,7 +14,7 @@ Lint/UselessAssignment:
|
|
14
14
|
# Offense count: 3
|
15
15
|
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
16
16
|
Metrics/AbcSize:
|
17
|
-
Max:
|
17
|
+
Max: 55
|
18
18
|
|
19
19
|
# Offense count: 1
|
20
20
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
@@ -35,12 +35,12 @@ Metrics/MethodLength:
|
|
35
35
|
# Offense count: 1
|
36
36
|
# Configuration parameters: CountComments, CountAsOne.
|
37
37
|
Metrics/ModuleLength:
|
38
|
-
Max:
|
38
|
+
Max: 120
|
39
39
|
|
40
40
|
# Offense count: 1
|
41
41
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
42
42
|
Metrics/ParameterLists:
|
43
|
-
Max:
|
43
|
+
Max: 12
|
44
44
|
|
45
45
|
# Offense count: 2
|
46
46
|
# Configuration parameters: IgnoredMethods.
|
@@ -79,13 +79,13 @@ RSpec/FilePath:
|
|
79
79
|
- 'spec/content_metadata_spec.rb'
|
80
80
|
- 'spec/object_file_spec.rb'
|
81
81
|
|
82
|
-
# Offense count:
|
82
|
+
# Offense count: 74
|
83
83
|
# Configuration parameters: AssignmentOnly.
|
84
84
|
RSpec/InstanceVariable:
|
85
85
|
Exclude:
|
86
86
|
- 'spec/object_file_spec.rb'
|
87
87
|
|
88
|
-
# Offense count:
|
88
|
+
# Offense count: 40
|
89
89
|
RSpec/MultipleExpectations:
|
90
90
|
Max: 29
|
91
91
|
|
@@ -110,7 +110,7 @@ Style/CommentedKeyword:
|
|
110
110
|
Exclude:
|
111
111
|
- 'lib/assembly-objectfile/content_metadata.rb'
|
112
112
|
|
113
|
-
# Offense count:
|
113
|
+
# Offense count: 122
|
114
114
|
# Cop supports --auto-correct.
|
115
115
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
116
116
|
# URISchemes: http, https
|
data/lib/assembly-objectfile.rb
CHANGED
@@ -14,6 +14,14 @@ module Assembly
|
|
14
14
|
# by the file command, then a check will be made to see if exif data exists...if so, the mimetype returned by the exif data will be used
|
15
15
|
# if no exif data exists, then the mimetype returned by the unix file command will be used
|
16
16
|
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml'].freeze
|
17
|
+
|
18
|
+
# this is a manual override mapping of file extension to mimetype; if a file with the given extension is found, the mapped
|
19
|
+
# mimetype will be returned and no further methods will be used - this is used to force a specific mimetype to be returned for
|
20
|
+
# for a given file extension regardless of what exif or the unix file system command returns
|
21
|
+
# the mapping format is "extension with period: returned mimetype", e.g. for any .json file, you will always get `application/json`
|
22
|
+
OVERRIDE_MIMETYPES = {
|
23
|
+
'.json': 'application/json'
|
24
|
+
}.freeze
|
17
25
|
end
|
18
26
|
|
19
27
|
require 'assembly-objectfile/content_metadata'
|
@@ -8,7 +8,7 @@ module Assembly
|
|
8
8
|
module ObjectFileable
|
9
9
|
attr_accessor :file_attributes, :label, :path, :provider_md5, :provider_sha1, :relative_path, :mime_type_order
|
10
10
|
|
11
|
-
VALID_MIMETYPE_METHODS = %i[exif file extension].freeze
|
11
|
+
VALID_MIMETYPE_METHODS = %i[override exif file extension].freeze
|
12
12
|
|
13
13
|
# @param [String] path full path to the file to be worked with
|
14
14
|
# @param [Hash<Symbol => Object>] params options used during content metadata generation
|
@@ -18,7 +18,8 @@ module Assembly
|
|
18
18
|
# @option params [String] :provider_sha1 pre-computed SHA1 checksum
|
19
19
|
# @option params [String] :relative_path if you want the file ids in the content metadata it can be set, otherwise content metadata will get the full path
|
20
20
|
# @option params [Array] :mime_type_order can be set to the order in which you want mimetypes to be determined
|
21
|
-
# options are :
|
21
|
+
# options are :override (from manual overide mapping if exists), :exif (from exif if exists),
|
22
|
+
# :extension (from file extension), and :file (from unix file system command)
|
22
23
|
# the default is defined in the private `default_mime_type_order` method but you can override to set your own order
|
23
24
|
# @example
|
24
25
|
# Assembly::ObjectFile.new('/input/path_to_file.tif')
|
@@ -127,12 +128,21 @@ module Assembly
|
|
127
128
|
mimetype = ''
|
128
129
|
mime_type_order.each do |mime_type_method|
|
129
130
|
mimetype = public_send("#{mime_type_method}_mimetype") if VALID_MIMETYPE_METHODS.include?(mime_type_method)
|
130
|
-
break if
|
131
|
+
break if mimetype.present?
|
131
132
|
end
|
132
133
|
mimetype
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
137
|
+
# Returns mimetype information using the manual override mapping (based on a file extension lookup)
|
138
|
+
# @return [String] mime type for supplied file if a mapping exists for the file's extension
|
139
|
+
# @example
|
140
|
+
# source_file = Assembly::ObjectFile.new('/input/path_to_file.json')
|
141
|
+
# puts source_file.override_mimetype # 'application/json'
|
142
|
+
def override_mimetype
|
143
|
+
@override_mimetype ||= Assembly::OVERRIDE_MIMETYPES.fetch(ext.to_sym, '')
|
144
|
+
end
|
145
|
+
|
136
146
|
# Returns mimetype information using the mime-types gem (based on a file extension lookup)
|
137
147
|
# @return [String] mime type for supplied file
|
138
148
|
# @example
|
@@ -257,7 +267,7 @@ exif&.mimetype && prefer_exif
|
|
257
267
|
|
258
268
|
# prive method defining default preferred ordering of how mimetypes are determined
|
259
269
|
def default_mime_type_order
|
260
|
-
%i[exif file extension]
|
270
|
+
%i[override exif file extension]
|
261
271
|
end
|
262
272
|
|
263
273
|
# private method to check for file existence before operating on it
|
data/spec/object_file_spec.rb
CHANGED
@@ -70,6 +70,13 @@ describe Assembly::ObjectFile do
|
|
70
70
|
expect(@ai.mimetype).to eq('text/plain')
|
71
71
|
end
|
72
72
|
|
73
|
+
it 'overrides the mimetype generators and uses the manual mapping to set the correct mimetype of application/json for a .json file' do
|
74
|
+
@ai = described_class.new(TEST_JSON_FILE)
|
75
|
+
expect(@ai.exif_mimetype).to be_nil # exif returns nil
|
76
|
+
expect(@ai.file_mimetype).to eq('text/plain') # unix file system command returns plain text
|
77
|
+
expect(@ai.mimetype).to eq('application/json') # but our configured mapping overrides both and returns application/json
|
78
|
+
end
|
79
|
+
|
73
80
|
it 'sets the correct mimetype of image/tiff for .tif files' do
|
74
81
|
@ai = described_class.new(TEST_TIF_INPUT_FILE)
|
75
82
|
expect(@ai.mimetype).to eq('image/tiff')
|
data/spec/spec_helper.rb
CHANGED
@@ -54,6 +54,8 @@ TEST_RES3_TEI = File.join(TEST_INPUT_DIR, 'res3_teifile.txt')
|
|
54
54
|
|
55
55
|
TEST_FILE_NO_EXIF = File.join(TEST_INPUT_DIR, 'file_with_no_exif.xml')
|
56
56
|
|
57
|
+
TEST_JSON_FILE = File.join(TEST_INPUT_DIR, 'test.json')
|
58
|
+
|
57
59
|
TEST_OBJ_FILE = File.join(TEST_INPUT_DIR, 'someobject.obj')
|
58
60
|
TEST_PLY_FILE = File.join(TEST_INPUT_DIR, 'someobject.ply')
|
59
61
|
|
@@ -0,0 +1 @@
|
|
1
|
+
{some: 'thing'}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assembly-objectfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-04-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -263,6 +263,7 @@ files:
|
|
263
263
|
- spec/test_data/input/someobject.obj
|
264
264
|
- spec/test_data/input/someobject.ply
|
265
265
|
- spec/test_data/input/test.jp2
|
266
|
+
- spec/test_data/input/test.json
|
266
267
|
- spec/test_data/input/test.pdf
|
267
268
|
- spec/test_data/input/test.tif
|
268
269
|
- spec/test_data/input/test2.jp2
|
@@ -287,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
287
288
|
- !ruby/object:Gem::Version
|
288
289
|
version: '0'
|
289
290
|
requirements: []
|
290
|
-
rubygems_version: 3.2.
|
291
|
+
rubygems_version: 3.2.16
|
291
292
|
signing_key:
|
292
293
|
specification_version: 4
|
293
294
|
summary: Ruby immplementation of file services needed to prepare objects to be accessioned
|
@@ -326,6 +327,7 @@ test_files:
|
|
326
327
|
- spec/test_data/input/someobject.obj
|
327
328
|
- spec/test_data/input/someobject.ply
|
328
329
|
- spec/test_data/input/test.jp2
|
330
|
+
- spec/test_data/input/test.json
|
329
331
|
- spec/test_data/input/test.pdf
|
330
332
|
- spec/test_data/input/test.tif
|
331
333
|
- spec/test_data/input/test2.jp2
|