assembly-objectfile 2.1.0 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +2 -2
- data/Gemfile.lock +11 -11
- data/lib/assembly/object_file/version.rb +1 -1
- data/lib/assembly/object_file.rb +29 -106
- data/lib/assembly-objectfile.rb +2 -4
- data/spec/assembly/object_file_spec.rb +38 -46
- data/spec/spec_helper.rb +2 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6743d03c8c75529ad425586ed16bece4858c1fd2394342918ab29c568199d4f7
|
4
|
+
data.tar.gz: 16a79c4115124aae1402f1651076a85eb58912b4309f5a7503536246cd55076f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f08d614455304c1d7c935bc5e69ca85400493b8ba4bb045d048dc519c5a78f401d2d7e1a62292a8048cc0e9b83bdd0bc3f9fa540e8021356f9929ba3ec72ef37
|
7
|
+
data.tar.gz: 2340e0deff59c7e913272c6c18ce6f27513d2b1777e7d7da9120a4b3377f00c80ae2c59e31c3c29769ae763dc2cc4888b3bbdc76ce75f6962b81b2de713d4551
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2022-07-
|
3
|
+
# on 2022-07-20 17:16:46 UTC using RuboCop version 1.31.2.
|
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
|
@@ -9,4 +9,4 @@
|
|
9
9
|
# Offense count: 1
|
10
10
|
# Configuration parameters: CountComments, CountAsOne.
|
11
11
|
Metrics/ClassLength:
|
12
|
-
Max:
|
12
|
+
Max: 122
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
assembly-objectfile (2.1.
|
4
|
+
assembly-objectfile (2.1.3)
|
5
5
|
activesupport (>= 5.2.0)
|
6
6
|
mime-types (> 3)
|
7
7
|
mini_exiftool
|
@@ -28,16 +28,16 @@ GEM
|
|
28
28
|
mime-types-data (~> 3.2015)
|
29
29
|
mime-types-data (3.2022.0105)
|
30
30
|
mini_exiftool (2.10.2)
|
31
|
-
minitest (5.16.
|
31
|
+
minitest (5.16.3)
|
32
32
|
parallel (1.22.1)
|
33
|
-
parser (3.1.2.
|
33
|
+
parser (3.1.2.1)
|
34
34
|
ast (~> 2.4.1)
|
35
|
-
pry (0.
|
35
|
+
pry (0.14.1)
|
36
36
|
coderay (~> 1.1)
|
37
37
|
method_source (~> 1.0)
|
38
|
-
pry-byebug (3.
|
38
|
+
pry-byebug (3.10.1)
|
39
39
|
byebug (~> 11.0)
|
40
|
-
pry (
|
40
|
+
pry (>= 0.13, < 0.15)
|
41
41
|
rainbow (3.1.1)
|
42
42
|
rake (13.0.6)
|
43
43
|
regexp_parser (2.5.0)
|
@@ -55,17 +55,17 @@ GEM
|
|
55
55
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
56
|
rspec-support (~> 3.11.0)
|
57
57
|
rspec-support (3.11.0)
|
58
|
-
rubocop (1.
|
58
|
+
rubocop (1.35.1)
|
59
59
|
json (~> 2.3)
|
60
60
|
parallel (~> 1.10)
|
61
|
-
parser (>= 3.1.
|
61
|
+
parser (>= 3.1.2.1)
|
62
62
|
rainbow (>= 2.2.2, < 4.0)
|
63
63
|
regexp_parser (>= 1.8, < 3.0)
|
64
64
|
rexml (>= 3.2.5, < 4.0)
|
65
|
-
rubocop-ast (>= 1.
|
65
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
66
66
|
ruby-progressbar (~> 1.7)
|
67
67
|
unicode-display_width (>= 1.4.0, < 3.0)
|
68
|
-
rubocop-ast (1.
|
68
|
+
rubocop-ast (1.21.0)
|
69
69
|
parser (>= 3.1.1.0)
|
70
70
|
rubocop-rspec (2.12.1)
|
71
71
|
rubocop (~> 1.31)
|
@@ -76,7 +76,7 @@ GEM
|
|
76
76
|
simplecov_json_formatter (~> 0.1)
|
77
77
|
simplecov-html (0.12.3)
|
78
78
|
simplecov_json_formatter (0.1.4)
|
79
|
-
tzinfo (2.0.
|
79
|
+
tzinfo (2.0.5)
|
80
80
|
concurrent-ruby (~> 1.0)
|
81
81
|
unicode-display_width (2.2.0)
|
82
82
|
|
data/lib/assembly/object_file.rb
CHANGED
@@ -7,11 +7,8 @@ require 'active_support/core_ext/object/blank'
|
|
7
7
|
module Assembly
|
8
8
|
# This class contains generic methods to operate on any file.
|
9
9
|
class ObjectFile
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
# @param [Array] strings Array of filenames with paths to operate on
|
14
|
-
# @return [String] longest common initial part of path of filenames passed in
|
10
|
+
# @param [Array] strings Array of filenames with paths
|
11
|
+
# @return [String] longest common initial path of filenames passed in
|
15
12
|
#
|
16
13
|
# Example:
|
17
14
|
# puts Assembly::ObjectFile.common_prefix(['/Users/peter/00/test.tif','/Users/peter/05/test.jp2'])
|
@@ -52,8 +49,6 @@ module Assembly
|
|
52
49
|
# :file (from unix file system command)
|
53
50
|
# the default is defined in the private `default_mime_type_order` method
|
54
51
|
# but you can override to set your own order
|
55
|
-
# @example
|
56
|
-
# Assembly::ObjectFile.new('/input/path_to_file.tif')
|
57
52
|
def initialize(path, params = {})
|
58
53
|
@path = path
|
59
54
|
@label = params[:label]
|
@@ -64,64 +59,41 @@ module Assembly
|
|
64
59
|
@mime_type_order = params[:mime_type_order] || default_mime_type_order
|
65
60
|
end
|
66
61
|
|
67
|
-
# @return [String] base filename
|
68
|
-
# @example
|
69
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
70
|
-
# puts source_file.filename # "path_to_file.tif"
|
71
62
|
def filename
|
72
63
|
File.basename(path)
|
73
64
|
end
|
74
65
|
|
75
|
-
# @return [String] base directory
|
76
|
-
# @example
|
77
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
78
|
-
# puts source_file.dirname # "/input"
|
79
66
|
def dirname
|
80
67
|
File.dirname(path)
|
81
68
|
end
|
82
69
|
|
83
|
-
# @return [String] filename extension
|
84
|
-
# @example
|
85
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
86
|
-
# puts source_file.ext # ".tif"
|
87
70
|
def ext
|
88
71
|
File.extname(path)
|
89
72
|
end
|
90
73
|
|
91
|
-
# @return [String] base filename without extension
|
92
|
-
# @example
|
93
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
94
|
-
# puts source_file.filename # "path_to_file"
|
95
74
|
def filename_without_ext
|
96
75
|
File.basename(path, ext)
|
97
76
|
end
|
98
77
|
|
99
|
-
# @return [MiniExiftool] exif
|
100
|
-
# @example
|
101
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
102
|
-
# puts source_file.exif # hash with exif information
|
78
|
+
# @return [MiniExiftool] exif mini_exiftool gem object wrapper for exiftool
|
103
79
|
def exif
|
104
80
|
@exif ||= begin
|
105
81
|
check_for_file
|
106
82
|
MiniExiftool.new(path, replace_invalid_chars: '?')
|
83
|
+
rescue MiniExiftool::Error
|
84
|
+
# MiniExiftool may raise an error on files it doesn't know how to handle (disk images for example)
|
85
|
+
# but we don't want this to prevent an ObjectFile from being created, so just swallow it.
|
86
|
+
nil
|
107
87
|
end
|
108
88
|
end
|
109
89
|
|
110
|
-
#
|
111
|
-
# @return [String] md5 checksum
|
112
|
-
# @example
|
113
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
114
|
-
# puts source_file.md5 # 'XXX123XXX1243XX1243'
|
90
|
+
# @return [String] computed md5 checksum
|
115
91
|
def md5
|
116
92
|
check_for_file unless @md5
|
117
93
|
@md5 ||= Digest::MD5.file(path).hexdigest
|
118
94
|
end
|
119
95
|
|
120
|
-
#
|
121
|
-
# @return [String] sha1 checksum
|
122
|
-
# @example
|
123
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
124
|
-
# puts source_file.sha1 # 'XXX123XXX1243XX1243'
|
96
|
+
# @return [String] computed sha1 checksum
|
125
97
|
def sha1
|
126
98
|
check_for_file unless @sha1
|
127
99
|
@sha1 ||= Digest::SHA1.file(path).hexdigest
|
@@ -129,10 +101,7 @@ module Assembly
|
|
129
101
|
|
130
102
|
# Returns mimetype information for the current file based on the ordering set in default_mime_type_order
|
131
103
|
# We stop computing mimetypes as soon as we have a method that returns a value
|
132
|
-
# @return [String]
|
133
|
-
# @example
|
134
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
135
|
-
# puts source_file.mimetype # 'text/plain'
|
104
|
+
# @return [String] mimetype of the file
|
136
105
|
def mimetype
|
137
106
|
@mimetype ||= begin
|
138
107
|
check_for_file
|
@@ -147,84 +116,60 @@ module Assembly
|
|
147
116
|
|
148
117
|
# @return [Symbol] the type of object, could be :application (for PDF or Word, etc),
|
149
118
|
# :audio, :image, :message, :model, :multipart, :text or :video
|
150
|
-
# @example
|
151
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
152
|
-
# puts source_file.object_type # :image
|
153
119
|
def object_type
|
154
120
|
lookup = MIME::Types[mimetype][0]
|
155
121
|
lookup.nil? ? :other : lookup.media_type.to_sym
|
156
122
|
end
|
157
123
|
|
158
|
-
# @return [Boolean] if
|
159
|
-
# @example
|
160
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
161
|
-
# puts source_file.image? # true
|
124
|
+
# @return [Boolean] true if the mime-types gem recognizes it as an image
|
162
125
|
def image?
|
163
|
-
object_type
|
126
|
+
return false if object_type != :image
|
127
|
+
|
128
|
+
# We exclude TARGA images here because we've seen where the file is a disk image and
|
129
|
+
# when we look for a mime type it is `image/x-tga', however it is not
|
130
|
+
# recognizable by exiftool. See https://github.com/sul-dlss/assembly-objectfile/issues/98
|
131
|
+
mimetype != 'image/x-tga'
|
164
132
|
end
|
165
133
|
|
166
|
-
#
|
167
|
-
#
|
168
|
-
# @return [Boolean] true if image is valid, false if not.
|
169
|
-
# @example
|
170
|
-
# source_img = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
171
|
-
# puts source_img.valid_image? # true
|
134
|
+
# @return [Boolean] true if the mime-types gem recognizes it as an image
|
135
|
+
# AND it is a jp2 or jp2able?
|
172
136
|
def valid_image?
|
173
137
|
return false unless image?
|
174
138
|
|
175
139
|
mimetype == 'image/jp2' || jp2able?
|
176
140
|
end
|
177
141
|
|
178
|
-
#
|
179
|
-
# the existence of a profile description and further restricts mimetypes.
|
180
|
-
# It is used by the assembly robots to decide if a jp2 will be created and is also called before
|
181
|
-
# you create a jp2 using assembly-image.
|
182
|
-
# @return [Boolean] true if image should have a jp2 created, false if not.
|
183
|
-
# @example
|
184
|
-
# source_img = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
185
|
-
# puts source_img.jp2able? # true
|
142
|
+
# @return [Boolean] true if we can create a jp2 from the file
|
186
143
|
def jp2able?
|
187
144
|
return false unless exif
|
188
145
|
|
189
146
|
Assembly::VALID_IMAGE_MIMETYPES.include?(mimetype)
|
190
147
|
end
|
191
148
|
|
192
|
-
# Returns file size information for the current file in bytes.
|
193
149
|
# @return [Integer] file size in bytes
|
194
|
-
# @example
|
195
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
196
|
-
# puts source_file.filesize # 1345
|
197
150
|
def filesize
|
198
151
|
check_for_file
|
199
152
|
@filesize ||= File.size(path)
|
200
153
|
end
|
201
154
|
|
202
|
-
#
|
203
|
-
# @return [Boolean] file exists
|
204
|
-
# @example
|
205
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.tif')
|
206
|
-
# puts source_file.file_exists? # true
|
155
|
+
# @return [Boolean] file exists and is not a directory
|
207
156
|
def file_exists?
|
208
157
|
@file_exists ||= (File.exist?(path) && !File.directory?(path))
|
209
158
|
end
|
210
159
|
|
211
160
|
private
|
212
161
|
|
213
|
-
#
|
162
|
+
# check for file existence before operating on it
|
214
163
|
def check_for_file
|
215
164
|
raise "input file #{path} does not exist or is a directory" unless file_exists?
|
216
165
|
end
|
217
166
|
|
218
|
-
#
|
167
|
+
# defines default preferred ordering of how mimetypes are determined
|
219
168
|
def default_mime_type_order
|
220
169
|
%i[override exif file extension]
|
221
170
|
end
|
222
171
|
|
223
|
-
#
|
224
|
-
# @return [String] mime type for supplied file
|
225
|
-
# @example
|
226
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
227
|
-
# puts source_file.extension_mimetype # 'text/plain'
|
172
|
+
# @return [String] mime type for supplied file using the mime-types gem (based on a file extension lookup)
|
228
173
|
def extension_mimetype
|
229
174
|
@extension_mimetype ||= begin
|
230
175
|
mtype = MIME::Types.type_for(path).first
|
@@ -232,11 +177,7 @@ module Assembly
|
|
232
177
|
end
|
233
178
|
end
|
234
179
|
|
235
|
-
#
|
236
|
-
# @return [String] mime type for supplied file
|
237
|
-
# @example
|
238
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
239
|
-
# puts source_file.file_mimetype # 'text/plain'
|
180
|
+
# @return [String] mime type for supplied file based on unix file system command
|
240
181
|
def file_mimetype
|
241
182
|
@file_mimetype ||= begin
|
242
183
|
check_for_file
|
@@ -244,40 +185,22 @@ module Assembly
|
|
244
185
|
end
|
245
186
|
end
|
246
187
|
|
247
|
-
#
|
248
|
-
#
|
249
|
-
#
|
250
|
-
# @example
|
251
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
252
|
-
# puts source_file.exif_mimetype # 'text/plain'
|
188
|
+
# @return [String] mimetype information for the current file based on exif data,
|
189
|
+
# unless mimetype is configured as one we'd rather get from the file system command
|
190
|
+
# (e.g. exif struggles or we get better info from file system command)
|
253
191
|
def exif_mimetype
|
254
192
|
@exif_mimetype ||= begin
|
255
193
|
check_for_file
|
256
194
|
# if it's not a "trusted" mimetype and there is exif data; get the mimetype from the exif
|
257
195
|
prefer_exif = !Assembly::TRUSTED_MIMETYPES.include?(file_mimetype)
|
258
|
-
exif.mimetype if exif&.mimetype
|
196
|
+
exif.mimetype if prefer_exif && exif&.mimetype
|
259
197
|
end
|
260
198
|
end
|
261
199
|
|
262
200
|
# Returns mimetype information using the manual override mapping (based on a file extension lookup)
|
263
201
|
# @return [String] mime type for supplied file if a mapping exists for the file's extension
|
264
|
-
# @example
|
265
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.json')
|
266
|
-
# puts source_file.override_mimetype # 'application/json'
|
267
202
|
def override_mimetype
|
268
203
|
@override_mimetype ||= Assembly::OVERRIDE_MIMETYPES.fetch(ext.to_sym, '')
|
269
204
|
end
|
270
|
-
|
271
|
-
# @note Uses shell call to "file", only expected to work on unix based systems
|
272
|
-
# @return [String] encoding for supplied file
|
273
|
-
# @example
|
274
|
-
# source_file = Assembly::ObjectFile.new('/input/path_to_file.txt')
|
275
|
-
# puts source_file.encoding # 'us-ascii'
|
276
|
-
def encoding
|
277
|
-
@encoding ||= begin
|
278
|
-
check_for_file
|
279
|
-
`file --mime-encoding "#{path}"`.delete("\n").split(':')[1].strip
|
280
|
-
end
|
281
|
-
end
|
282
205
|
end
|
283
206
|
end
|
data/lib/assembly-objectfile.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Assembly
|
4
|
-
# the path to the gem, used to access profiles stored with the gem
|
5
|
-
PATH_TO_GEM = File.expand_path("#{File.dirname(__FILE__)}/..")
|
6
|
-
|
7
4
|
# If input image is not one of these mime types, it will not be regarded as a valid image
|
8
5
|
# for the purpose of generating a JP2 derivative
|
9
6
|
VALID_IMAGE_MIMETYPES = ['image/jpeg', 'image/tiff', 'image/tif', 'image/png'].freeze
|
@@ -12,7 +9,8 @@ module Assembly
|
|
12
9
|
# one of these is returned by the file command, then a check will be made to see if exif data exists...
|
13
10
|
# if so, the mimetype returned by the exif data will be used if no exif data exists, then the
|
14
11
|
# mimetype returned by the unix file command will be used
|
15
|
-
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml'
|
12
|
+
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml',
|
13
|
+
'application/octet-stream'].freeze
|
16
14
|
|
17
15
|
# This is a manual override mapping of file extension to mimetype; if a file with the given extension
|
18
16
|
# is found, the mapped mimetype will be returned and no further methods will be used - this is used
|
@@ -97,34 +97,41 @@ describe Assembly::ObjectFile do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
describe '#image?' do
|
100
|
+
subject { object_file.image? }
|
101
|
+
|
100
102
|
context 'with tiff' do
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
103
|
+
let(:object_file) { described_class.new(TEST_TIF_INPUT_FILE) }
|
104
|
+
|
105
|
+
it { is_expected.to be true }
|
105
106
|
end
|
106
107
|
|
107
108
|
context 'with jp2' do
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
let(:object_file) { described_class.new(TEST_JP2_INPUT_FILE) }
|
110
|
+
|
111
|
+
it { is_expected.to be true }
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with targa file' do
|
115
|
+
before do
|
116
|
+
allow(object_file).to receive(:exif_mimetype).and_return(nil)
|
117
|
+
allow(object_file).to receive(:file_mimetype).and_return('image/x-tga')
|
111
118
|
end
|
119
|
+
|
120
|
+
let(:object_file) { described_class.new(TEST_JP2_INPUT_FILE) }
|
121
|
+
|
122
|
+
it { is_expected.to be false }
|
112
123
|
end
|
113
124
|
|
114
125
|
context 'with ruby file' do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
expect(object_file.image?).to be(false)
|
119
|
-
end
|
126
|
+
let(:object_file) { described_class.new(File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')) }
|
127
|
+
|
128
|
+
it { is_expected.to be false }
|
120
129
|
end
|
121
130
|
|
122
131
|
context 'with xml' do
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
expect(object_file.image?).to be(false)
|
127
|
-
end
|
132
|
+
let(:object_file) { described_class.new(File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')) }
|
133
|
+
|
134
|
+
it { is_expected.to be false }
|
128
135
|
end
|
129
136
|
end
|
130
137
|
|
@@ -145,7 +152,7 @@ describe Assembly::ObjectFile do
|
|
145
152
|
|
146
153
|
context 'with ruby file' do
|
147
154
|
it ':text' do
|
148
|
-
non_image_file = File.join(
|
155
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
|
149
156
|
object_file = described_class.new(non_image_file)
|
150
157
|
expect(object_file.object_type).to eq(:text)
|
151
158
|
end
|
@@ -153,7 +160,7 @@ describe Assembly::ObjectFile do
|
|
153
160
|
|
154
161
|
context 'with xml' do
|
155
162
|
it ':application' do
|
156
|
-
non_image_file = File.join(
|
163
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
|
157
164
|
object_file = described_class.new(non_image_file)
|
158
165
|
expect(object_file.object_type).to eq(:application)
|
159
166
|
end
|
@@ -191,7 +198,7 @@ describe Assembly::ObjectFile do
|
|
191
198
|
|
192
199
|
context 'with ruby file' do
|
193
200
|
it 'false' do
|
194
|
-
non_image_file = File.join(
|
201
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
|
195
202
|
object_file = described_class.new(non_image_file)
|
196
203
|
expect(object_file.valid_image?).to be(false)
|
197
204
|
end
|
@@ -199,7 +206,7 @@ describe Assembly::ObjectFile do
|
|
199
206
|
|
200
207
|
context 'with xml' do
|
201
208
|
it 'false' do
|
202
|
-
non_image_file = File.join(
|
209
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
|
203
210
|
object_file = described_class.new(non_image_file)
|
204
211
|
expect(object_file.valid_image?).to be(false)
|
205
212
|
end
|
@@ -359,7 +366,7 @@ describe Assembly::ObjectFile do
|
|
359
366
|
|
360
367
|
describe '#file_exists?' do
|
361
368
|
it 'false when a valid directory is specified instead of a file' do
|
362
|
-
path =
|
369
|
+
path = PATH_TO_GEM
|
363
370
|
object_file = described_class.new(path)
|
364
371
|
expect(File.exist?(path)).to be true
|
365
372
|
expect(File.directory?(path)).to be true
|
@@ -367,7 +374,7 @@ describe Assembly::ObjectFile do
|
|
367
374
|
end
|
368
375
|
|
369
376
|
it 'false when a non-existent file is specified' do
|
370
|
-
path = File.join(
|
377
|
+
path = File.join(PATH_TO_GEM, 'file_not_there.txt')
|
371
378
|
object_file = described_class.new(path)
|
372
379
|
expect(File.exist?(path)).to be false
|
373
380
|
expect(File.directory?(path)).to be false
|
@@ -387,32 +394,17 @@ describe Assembly::ObjectFile do
|
|
387
394
|
end
|
388
395
|
end
|
389
396
|
|
390
|
-
describe '#
|
391
|
-
|
392
|
-
it 'binary' do
|
393
|
-
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
394
|
-
expect(object_file.send(:encoding)).to eq('binary')
|
395
|
-
end
|
396
|
-
end
|
397
|
+
describe '#exif' do
|
398
|
+
subject(:exif) { object_file.exif }
|
397
399
|
|
398
|
-
|
399
|
-
it 'binary' do
|
400
|
-
object_file = described_class.new(TEST_RES1_TEXT)
|
401
|
-
expect(object_file.send(:encoding)).to eq('us-ascii')
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
400
|
+
let(:object_file) { described_class.new(TEST_TIF_INPUT_FILE) }
|
405
401
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
expect(object_file.exif.class).to eq MiniExiftool
|
411
|
-
end
|
402
|
+
it { is_expected.to be_kind_of MiniExiftool }
|
403
|
+
|
404
|
+
context 'when exiftool raises an error initializing the file' do
|
405
|
+
let(:object_file) { described_class.new('spec/test_data/empty.txt') }
|
412
406
|
|
413
|
-
|
414
|
-
object_file = described_class.new('spec/test_data/empty.txt')
|
415
|
-
expect { object_file.exif }.to raise_error(MiniExiftool::Error)
|
407
|
+
it { is_expected.to be_nil }
|
416
408
|
end
|
417
409
|
end
|
418
410
|
|
data/spec/spec_helper.rb
CHANGED
@@ -10,13 +10,10 @@ RSpec.configure do |config|
|
|
10
10
|
config.order = 'random'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
TEST_INPUT_DIR = File.join(
|
15
|
-
TEST_OUTPUT_DIR = File.join(TEST_DATA_DIR, 'output')
|
13
|
+
PATH_TO_GEM = File.expand_path("#{File.dirname(__FILE__)}/..")
|
14
|
+
TEST_INPUT_DIR = File.join(PATH_TO_GEM, 'spec', 'test_data', 'input')
|
16
15
|
TEST_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.tif')
|
17
|
-
TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
|
18
16
|
TEST_JP2_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jp2')
|
19
|
-
TEST_JP2_OUTPUT_FILE = File.join(TEST_OUTPUT_DIR, 'test.jp2')
|
20
17
|
|
21
18
|
TEST_TIFF_NO_COLOR_FILE = File.join(TEST_INPUT_DIR, 'test_no_color_profile.tif')
|
22
19
|
|
@@ -30,5 +27,3 @@ TEST_JSON_FILE = File.join(TEST_INPUT_DIR, 'test.json')
|
|
30
27
|
|
31
28
|
TEST_OBJ_FILE = File.join(TEST_INPUT_DIR, 'someobject.obj')
|
32
29
|
TEST_PLY_FILE = File.join(TEST_INPUT_DIR, 'someobject.ply')
|
33
|
-
|
34
|
-
TEST_DRUID = 'nx288wh8889'
|
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: 2.1.
|
4
|
+
version: 2.1.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: 2022-
|
14
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|