assembly-objectfile 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/pull_request_template.md +8 -1
- data/.rubocop.yml +98 -1
- data/.rubocop_todo.yml +22 -21
- data/README.md +1 -1
- data/assembly-objectfile.gemspec +3 -1
- data/config/boot.rb +2 -2
- data/lib/assembly-objectfile/content_metadata/config.rb +3 -1
- data/lib/assembly-objectfile/content_metadata/file.rb +1 -1
- data/lib/assembly-objectfile/content_metadata/file_set.rb +2 -4
- data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +2 -0
- data/lib/assembly-objectfile/content_metadata.rb +11 -9
- data/lib/assembly-objectfile/object_file.rb +3 -3
- data/lib/assembly-objectfile/object_fileable.rb +21 -10
- data/lib/assembly-objectfile/version.rb +1 -1
- data/lib/assembly-objectfile.rb +9 -1
- data/spec/content_metadata_spec.rb +550 -491
- data/spec/object_file_spec.rb +7 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/test_data/input/test.json +1 -0
- metadata +13 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f0c15e9e8be693ac604d4f4f440a62b8c91d4e10e1605d78ecf487b45aa231b
|
4
|
+
data.tar.gz: 1441b9f02785c6397cfee954382b4b0de92e006457b0a5bfce42111b4f1ee634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b12637ddf0e5110ada401dfd04f35072a42046c02fabd1446139f5c387f31bf82fb82ff6b95621f1f182f839ad50b2f66f529ddff61c79979a0c248659dd7947
|
7
|
+
data.tar.gz: f2bf8dcce09af5ac5f499ffff3abafd8ef01b03a30ceb249a590da75b594fd96dcd8a0e73b295ff37ca52825941c5b2892ed05c1746a9de5d85e048138f7e67b
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
inherit_from: .rubocop_todo.yml
|
2
2
|
require: rubocop-rspec
|
3
3
|
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.5
|
6
|
+
|
4
7
|
RSpec/ContextWording:
|
5
8
|
Enabled: false # too dogmatic
|
6
9
|
|
@@ -16,11 +19,69 @@ RSpec/NestedGroups:
|
|
16
19
|
|
17
20
|
Metrics/BlockLength:
|
18
21
|
Exclude:
|
19
|
-
- spec
|
22
|
+
- 'spec/**/*.rb'
|
23
|
+
- '**/*.gemspec'
|
24
|
+
|
25
|
+
Gemspec/DateAssignment: # (new in 1.10)
|
26
|
+
Enabled: true
|
20
27
|
|
21
28
|
Layout/SpaceAroundMethodCallOperator:
|
22
29
|
Enabled: true
|
23
30
|
|
31
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Lint/DuplicateBranch: # (new in 1.3)
|
44
|
+
Enabled: true
|
45
|
+
|
46
|
+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
Lint/EmptyBlock: # (new in 1.1)
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
Lint/EmptyClass: # (new in 1.3)
|
53
|
+
Enabled: true
|
54
|
+
|
55
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
56
|
+
Enabled: true
|
57
|
+
|
58
|
+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
Lint/NumberedParameterAssignment: # (new in 1.9)
|
62
|
+
Enabled: true
|
63
|
+
|
64
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
65
|
+
Enabled: true
|
66
|
+
|
67
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
Lint/SymbolConversion: # (new in 1.9)
|
71
|
+
Enabled: true
|
72
|
+
|
73
|
+
Lint/ToEnumArguments: # (new in 1.1)
|
74
|
+
Enabled: true
|
75
|
+
|
76
|
+
Lint/TripleQuotes: # (new in 1.9)
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Lint/UnexpectedBlockArity: # (new in 1.5)
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
83
|
+
Enabled: true
|
84
|
+
|
24
85
|
Lint/RaiseException:
|
25
86
|
Enabled: true
|
26
87
|
|
@@ -38,3 +99,39 @@ Style/HashTransformKeys:
|
|
38
99
|
|
39
100
|
Style/HashTransformValues:
|
40
101
|
Enabled: true
|
102
|
+
|
103
|
+
Style/SlicingWithRange:
|
104
|
+
Enabled: true
|
105
|
+
|
106
|
+
Style/ArgumentsForwarding: # (new in 1.1)
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
Style/CollectionCompact: # (new in 1.2)
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/EndlessMethod: # (new in 1.8)
|
116
|
+
Enabled: true
|
117
|
+
|
118
|
+
Style/HashConversion: # (new in 1.10)
|
119
|
+
Enabled: true
|
120
|
+
|
121
|
+
Style/HashExcept: # (new in 1.7)
|
122
|
+
Enabled: true
|
123
|
+
|
124
|
+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
125
|
+
Enabled: true
|
126
|
+
|
127
|
+
Style/NegatedIfElseCondition: # (new in 1.2)
|
128
|
+
Enabled: true
|
129
|
+
|
130
|
+
Style/NilLambda: # (new in 1.3)
|
131
|
+
Enabled: true
|
132
|
+
|
133
|
+
Style/RedundantArgument: # (new in 1.4)
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Style/SwapValues: # (new in 1.1)
|
137
|
+
Enabled: true
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
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
|
@@ -12,13 +12,13 @@ Lint/UselessAssignment:
|
|
12
12
|
- 'config/boot.rb'
|
13
13
|
|
14
14
|
# Offense count: 3
|
15
|
-
# Configuration parameters: IgnoredMethods.
|
15
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
16
16
|
Metrics/AbcSize:
|
17
|
-
Max:
|
17
|
+
Max: 55
|
18
18
|
|
19
|
-
# Offense count:
|
20
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
21
|
-
#
|
19
|
+
# Offense count: 1
|
20
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
21
|
+
# IgnoredMethods: refine
|
22
22
|
Metrics/BlockLength:
|
23
23
|
Max: 27
|
24
24
|
|
@@ -28,27 +28,27 @@ Metrics/CyclomaticComplexity:
|
|
28
28
|
Max: 14
|
29
29
|
|
30
30
|
# Offense count: 4
|
31
|
-
# Configuration parameters: CountComments, ExcludedMethods.
|
31
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
32
32
|
Metrics/MethodLength:
|
33
|
-
Max:
|
33
|
+
Max: 31
|
34
34
|
|
35
35
|
# Offense count: 1
|
36
|
-
# Configuration parameters: CountComments.
|
36
|
+
# Configuration parameters: CountComments, CountAsOne.
|
37
37
|
Metrics/ModuleLength:
|
38
|
-
Max:
|
38
|
+
Max: 120
|
39
39
|
|
40
40
|
# Offense count: 1
|
41
|
-
# Configuration parameters: CountKeywordArgs.
|
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.
|
47
47
|
Metrics/PerceivedComplexity:
|
48
|
-
Max:
|
48
|
+
Max: 15
|
49
49
|
|
50
50
|
# Offense count: 1
|
51
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
51
|
+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
52
52
|
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
53
53
|
Naming/FileName:
|
54
54
|
Exclude:
|
@@ -65,27 +65,27 @@ Naming/PredicateName:
|
|
65
65
|
- 'spec/**/*'
|
66
66
|
- 'lib/assembly-objectfile/object_fileable.rb'
|
67
67
|
|
68
|
-
# Offense count:
|
68
|
+
# Offense count: 9
|
69
69
|
# Configuration parameters: Max.
|
70
70
|
RSpec/ExampleLength:
|
71
71
|
Exclude:
|
72
72
|
- 'spec/content_metadata_spec.rb'
|
73
73
|
|
74
74
|
# Offense count: 2
|
75
|
-
# Configuration parameters: CustomTransform, IgnoreMethods.
|
75
|
+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
|
76
|
+
# Include: **/*_spec*rb*, **/spec/**/*
|
76
77
|
RSpec/FilePath:
|
77
78
|
Exclude:
|
78
79
|
- 'spec/content_metadata_spec.rb'
|
79
80
|
- 'spec/object_file_spec.rb'
|
80
81
|
|
81
|
-
# Offense count:
|
82
|
+
# Offense count: 74
|
82
83
|
# Configuration parameters: AssignmentOnly.
|
83
84
|
RSpec/InstanceVariable:
|
84
85
|
Exclude:
|
85
86
|
- 'spec/object_file_spec.rb'
|
86
87
|
|
87
|
-
# Offense count:
|
88
|
-
# Configuration parameters: AggregateFailuresByDefault.
|
88
|
+
# Offense count: 40
|
89
89
|
RSpec/MultipleExpectations:
|
90
90
|
Max: 29
|
91
91
|
|
@@ -105,13 +105,14 @@ RSpec/RepeatedExampleGroupDescription:
|
|
105
105
|
- 'spec/content_metadata_spec.rb'
|
106
106
|
|
107
107
|
# Offense count: 2
|
108
|
+
# Cop supports --auto-correct.
|
108
109
|
Style/CommentedKeyword:
|
109
110
|
Exclude:
|
110
111
|
- 'lib/assembly-objectfile/content_metadata.rb'
|
111
112
|
|
112
|
-
# Offense count:
|
113
|
+
# Offense count: 122
|
113
114
|
# Cop supports --auto-correct.
|
114
115
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
115
116
|
# URISchemes: http, https
|
116
117
|
Layout/LineLength:
|
117
|
-
Max:
|
118
|
+
Max: 277
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.
|
1
|
+
[![Build Status](https://travis-ci.com/sul-dlss/assembly-objectfile.svg?branch=main)](https://travis-ci.com/sul-dlss/assembly-objectfile)
|
2
2
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/2310962acce78d78e76c/test_coverage)](https://codeclimate.com/github/sul-dlss/assembly-objectfile/test_coverage)
|
3
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/2310962acce78d78e76c/maintainability)](https://codeclimate.com/github/sul-dlss/assembly-objectfile/maintainability)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/assembly-objectfile.svg)](https://badge.fury.io/rb/assembly-objectfile)
|
data/assembly-objectfile.gemspec
CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
|
+
s.required_ruby_version = '>= 2.5', '< 4'
|
24
|
+
|
23
25
|
s.add_dependency 'activesupport', '>= 5.2.0'
|
24
26
|
s.add_dependency 'deprecation'
|
25
27
|
s.add_dependency 'dry-struct', '~> 1.0'
|
@@ -33,5 +35,5 @@ Gem::Specification.new do |s|
|
|
33
35
|
s.add_development_dependency 'rspec', '~> 3.0'
|
34
36
|
s.add_development_dependency 'rubocop'
|
35
37
|
s.add_development_dependency 'rubocop-rspec'
|
36
|
-
s.add_development_dependency 'simplecov'
|
38
|
+
s.add_development_dependency 'simplecov', '~> 0.17.0' # CodeClimate cannot use SimpleCov >= 0.18.0 for generating test coverage
|
37
39
|
end
|
data/config/boot.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
|
5
5
|
environment = ENV['ENVIRONMENT'] ||= 'development'
|
6
|
-
project_root = File.expand_path(File.dirname(__FILE__)
|
6
|
+
project_root = File.expand_path("#{File.dirname(__FILE__)}/..")
|
7
7
|
|
8
8
|
# Load config for current environment.
|
9
|
-
$LOAD_PATH.unshift(project_root
|
9
|
+
$LOAD_PATH.unshift("#{project_root}/lib")
|
10
10
|
|
11
11
|
require 'assembly-objectfile'
|
@@ -12,13 +12,15 @@ module Assembly
|
|
12
12
|
|
13
13
|
# Represents a configuration for generating the content metadata
|
14
14
|
class Config < Dry::Struct
|
15
|
-
STYLES = %w[image file book map 3d document].freeze
|
15
|
+
STYLES = %w[image file book map 3d document webarchive-seed].freeze
|
16
|
+
READING_ORDERS = %w[ltr rtl].freeze
|
16
17
|
attribute :auto_labels, Types::Strict::Bool.default(true)
|
17
18
|
attribute :flatten_folder_structure, Types::Strict::Bool.default(false)
|
18
19
|
attribute :add_file_attributes, Types::Strict::Bool.default(false)
|
19
20
|
attribute :add_exif, Types::Strict::Bool.default(false)
|
20
21
|
attribute :file_attributes, Types::Strict::Hash.default({}.freeze)
|
21
22
|
attribute :type, Types::Strict::String.enum(*STYLES)
|
23
|
+
attribute :reading_order, Types::Strict::String.default('ltr').enum(*READING_ORDERS)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -9,7 +9,7 @@ module Assembly
|
|
9
9
|
# @param [Boolean] dpg (false) is it a dpg bundle?
|
10
10
|
# @param [Array<Assembly::ObjectFile>] resource_files
|
11
11
|
# @param style
|
12
|
-
def initialize(
|
12
|
+
def initialize(resource_files:, style:, dpg: false)
|
13
13
|
@dpg = dpg
|
14
14
|
@resource_files = resource_files
|
15
15
|
@style = style
|
@@ -46,7 +46,7 @@ module Assembly
|
|
46
46
|
resource_has_non_images = !(resource_file_types - [:image]).empty?
|
47
47
|
|
48
48
|
case style
|
49
|
-
when :simple_image
|
49
|
+
when :simple_image, :map, :'webarchive-seed'
|
50
50
|
'image'
|
51
51
|
when :file
|
52
52
|
'file'
|
@@ -56,8 +56,6 @@ module Assembly
|
|
56
56
|
resource_has_non_images && resource_file_types.include?(:image) == false ? 'object' : 'image'
|
57
57
|
when :book_with_pdf # in book with PDF type, if we find a resource with *any* non images, switch it's type from book to object
|
58
58
|
resource_has_non_images ? 'object' : 'page'
|
59
|
-
when :map
|
60
|
-
'image'
|
61
59
|
when :document
|
62
60
|
'document'
|
63
61
|
when :'3d'
|
@@ -15,6 +15,8 @@ module Assembly
|
|
15
15
|
|
16
16
|
Nokogiri::XML::Builder.new do |xml|
|
17
17
|
xml.contentMetadata(objectId: druid.to_s, type: config.type) do
|
18
|
+
xml.bookData(readingOrder: config.reading_order) if config.type == 'book'
|
19
|
+
|
18
20
|
filesets.each_with_index do |fileset, index| # iterate over all the resources
|
19
21
|
# start a new resource element
|
20
22
|
sequence = index + 1
|
@@ -14,7 +14,7 @@ module Assembly
|
|
14
14
|
# these are used when :bundle=>:dpg only
|
15
15
|
|
16
16
|
DEPRECATED_STYLES = %i[book_with_pdf book_as_image].freeze
|
17
|
-
VALID_STYLES = %i[simple_image simple_book file map document 3d].freeze
|
17
|
+
VALID_STYLES = %i[simple_image simple_book file map document 3d webarchive-seed].freeze
|
18
18
|
|
19
19
|
# This class generates content metadata for image files
|
20
20
|
class ContentMetadata
|
@@ -34,6 +34,7 @@ module Assembly
|
|
34
34
|
# :book_as_image, as simple_book, but with contentMetadata type="book", resource type="image" (same rule applies for resources with non images) - NOTE: THIS IS DEPRECATED
|
35
35
|
# :map, like simple_image, but with contentMetadata type="map", resource type="image"
|
36
36
|
# :3d, contentMetadata type="3d", ".obj" and other configured 3d extension files go into resource_type="3d", everything else into resource_type="file"
|
37
|
+
# :webarchive-seed, contentMetadata type="webarchive-seed", resource type="image"
|
37
38
|
# :bundle = optional - a symbol containing the method of bundling files into resources, allowed values are
|
38
39
|
# :default = all files get their own resources (default)
|
39
40
|
# :filename = files with the same filename but different extensions get bundled together in a single resource
|
@@ -51,13 +52,15 @@ module Assembly
|
|
51
52
|
# :flatten_folder_structure = optional - Will remove *all* folder structure when genearting file IDs (e.g. DPG subfolders like '00','05' will be removed) when generating file IDs. This is useful if the folder structure is flattened when staging files (like for DPG).
|
52
53
|
# The default is false. If set to true, will override the "preserve_common_paths" parameter.
|
53
54
|
# :auto_labels = optional - Will add automated resource labels (e.g. "File 1") when labels are not provided by the user. The default is true.
|
55
|
+
# See https://consul.stanford.edu/pages/viewpage.action?spaceKey=chimera&title=DOR+content+types%2C+resource+types+and+interpretive+metadata for next two settings
|
56
|
+
# :reading_order = optional - only valid for simple_book, can be 'rtl' or 'ltr'. The default is 'ltr'.
|
54
57
|
# Example:
|
55
58
|
# Assembly::ContentMetadata.create_content_metadata(:druid=>'druid:nx288wh8889',:style=>:simple_image,:objects=>object_files,:add_file_attributes=>false)
|
56
59
|
def self.create_content_metadata(druid:, objects:, auto_labels: true,
|
57
60
|
add_exif: false, bundle: :default, style: :simple_image,
|
58
61
|
add_file_attributes: false, file_attributes: {},
|
59
62
|
preserve_common_paths: false, flatten_folder_structure: false,
|
60
|
-
include_root_xml: nil)
|
63
|
+
include_root_xml: nil, reading_order: 'ltr')
|
61
64
|
|
62
65
|
common_path = find_common_path(objects) unless preserve_common_paths # find common paths to all files provided if needed
|
63
66
|
|
@@ -67,6 +70,7 @@ module Assembly
|
|
67
70
|
add_file_attributes: add_file_attributes,
|
68
71
|
file_attributes: file_attributes,
|
69
72
|
add_exif: add_exif,
|
73
|
+
reading_order: reading_order,
|
70
74
|
type: object_level_type(style))
|
71
75
|
|
72
76
|
builder = NokogiriBuilder.build(druid: druid,
|
@@ -74,13 +78,11 @@ module Assembly
|
|
74
78
|
common_path: common_path,
|
75
79
|
config: config)
|
76
80
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
result
|
81
|
+
if include_root_xml == false
|
82
|
+
builder.doc.root.to_xml
|
83
|
+
else
|
84
|
+
builder.to_xml
|
85
|
+
end
|
84
86
|
end
|
85
87
|
|
86
88
|
def self.special_dpg_folder?(folder)
|
@@ -19,10 +19,10 @@ module Assembly
|
|
19
19
|
x = strings.last
|
20
20
|
n += 1 while strings.all? { |s| s[n] && (s[n] == x[n]) }
|
21
21
|
common_prefix = x[0...n]
|
22
|
-
if common_prefix[-1, 1]
|
23
|
-
common_prefix
|
22
|
+
if common_prefix[-1, 1] == '/' # check if last element of the common string is the end of a directory
|
23
|
+
common_prefix # if not, split string along directories, and reject last one
|
24
24
|
else
|
25
|
-
common_prefix # if it was, then return the common prefix directly
|
25
|
+
"#{common_prefix.split('/')[0..-2].join('/')}/" # if it was, then return the common prefix directly
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -7,7 +7,8 @@ module Assembly
|
|
7
7
|
# Common behaviors we need for other classes in the gem
|
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[override exif file extension].freeze
|
11
12
|
|
12
13
|
# @param [String] path full path to the file to be worked with
|
13
14
|
# @param [Hash<Symbol => Object>] params options used during content metadata generation
|
@@ -17,7 +18,8 @@ module Assembly
|
|
17
18
|
# @option params [String] :provider_sha1 pre-computed SHA1 checksum
|
18
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
|
19
20
|
# @option params [Array] :mime_type_order can be set to the order in which you want mimetypes to be determined
|
20
|
-
# 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)
|
21
23
|
# the default is defined in the private `default_mime_type_order` method but you can override to set your own order
|
22
24
|
# @example
|
23
25
|
# Assembly::ObjectFile.new('/input/path_to_file.tif')
|
@@ -87,11 +89,11 @@ module Assembly
|
|
87
89
|
# puts source_file.exif # hash with exif information
|
88
90
|
def exif
|
89
91
|
@exif ||= begin
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
check_for_file
|
93
|
+
MiniExiftool.new(path, replace_invalid_chars: '?')
|
94
|
+
rescue StandardError
|
95
|
+
nil
|
96
|
+
end
|
95
97
|
end
|
96
98
|
|
97
99
|
# Computes md5 checksum or returns cached value
|
@@ -126,12 +128,21 @@ module Assembly
|
|
126
128
|
mimetype = ''
|
127
129
|
mime_type_order.each do |mime_type_method|
|
128
130
|
mimetype = public_send("#{mime_type_method}_mimetype") if VALID_MIMETYPE_METHODS.include?(mime_type_method)
|
129
|
-
break if
|
131
|
+
break if mimetype.present?
|
130
132
|
end
|
131
133
|
mimetype
|
132
134
|
end
|
133
135
|
end
|
134
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
|
+
|
135
146
|
# Returns mimetype information using the mime-types gem (based on a file extension lookup)
|
136
147
|
# @return [String] mime type for supplied file
|
137
148
|
# @example
|
@@ -208,7 +219,7 @@ exif&.mimetype && prefer_exif
|
|
208
219
|
def valid_image?
|
209
220
|
return false unless image?
|
210
221
|
|
211
|
-
mimetype == 'image/jp2' || jp2able?
|
222
|
+
mimetype == 'image/jp2' || jp2able?
|
212
223
|
end
|
213
224
|
|
214
225
|
# @return [Boolean] true if image has a color profile, false if not.
|
@@ -256,7 +267,7 @@ exif&.mimetype && prefer_exif
|
|
256
267
|
|
257
268
|
# prive method defining default preferred ordering of how mimetypes are determined
|
258
269
|
def default_mime_type_order
|
259
|
-
%i[exif file extension]
|
270
|
+
%i[override exif file extension]
|
260
271
|
end
|
261
272
|
|
262
273
|
# private method to check for file existence before operating on it
|
data/lib/assembly-objectfile.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Assembly
|
4
4
|
# the path to the gem, used to access profiles stored with the gem
|
5
|
-
PATH_TO_GEM = File.expand_path(File.dirname(__FILE__)
|
5
|
+
PATH_TO_GEM = File.expand_path("#{File.dirname(__FILE__)}/..")
|
6
6
|
|
7
7
|
# if input image is not one of these mime types, it will not be regarded as a valid image for the purpose of generating a JP2 derivative
|
8
8
|
VALID_IMAGE_MIMETYPES = ['image/jpeg', 'image/tiff', 'image/tif', 'image/png'].freeze
|
@@ -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'
|