valkyrie 3.1.4 → 3.2.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: 45ad037f0dbbaf39f2350701c25ec4820173455e80e094e6e18744cfb89effe5
4
- data.tar.gz: e8d6d55cc8f2694f1e8502e988a3ecb6609eca94307bef69707105594ea21b88
3
+ metadata.gz: 7439f8be7099e4b54998826abda9222d07226ff7a54fdb868f2ab7d99596fd56
4
+ data.tar.gz: 866c57941b2e2604a8d7bd8b013e0b31c07dd909404733cfb7043c61412389ad
5
5
  SHA512:
6
- metadata.gz: bce82f987a2916943fa4554985a049f1719cd67b89b206402f1e0dd4e8c622cda31f2c66d695e51e5209293a7d0b571d909795246bb3572f9c913b28010a14f8
7
- data.tar.gz: 8699c74af257248e5be5dbe03bbc47566beba045fa3450a2524e6b7f5a065f60012e27f96eb64f86351fec3336737b457a74f16079266aa135a535c9026ab86e
6
+ metadata.gz: 89d1857a2f40c0d8c32c6a31a9ff1247e9b8c32aa84e917c77c3d89e6a0cb52c7548802852914ddcf11d9805f3cf0b6784331f937cf9004b18e63ecb27449971
7
+ data.tar.gz: 5b143107a9ca53b86c83c5ba884635fb869919a7641c1373324193f9ac918684557177cf2c2519f5d8eeb0420bd48404037da5fb46c84d5a17bda0e4381b72f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ # v3.2.0 2024-04-10
2
+
3
+ ## Changes since last release
4
+
5
+ * Add cleanup functionality to StreamFile#disk_path. ([tpendragon](https://github.com/tpendragon))
6
+
7
+ Additional thanks to the following for code review and issue reports leading to this release:
8
+
9
+ * [dchandekstark](https://github.com/dchandekstark)
10
+ * [cgalarza](https://github.com/cgalarza)
11
+
12
+ # v3.1.5 2024-04-10
13
+
14
+ ## Changes since last release
15
+
16
+ * Add Valkyrie.root_path to access Valkyrie's gem location. ([tpendragon](https://github.com/tpendragon))
17
+
1
18
  # v3.1.4 2024-02-20
2
19
 
3
20
  ## Changes since last release
@@ -14,5 +14,13 @@ RSpec.shared_examples 'a Valkyrie::StorageAdapter::File' do
14
14
  it "returns an existing disk path" do
15
15
  expect(File.exist?(file.disk_path)).to eq true
16
16
  end
17
+ it "can accept a block" do
18
+ disk_path = nil
19
+ file.disk_path do |f_path|
20
+ expect(File.exist?(f_path)).to eq true
21
+ disk_path = f_path
22
+ end
23
+ expect(disk_path).not_to be_nil
24
+ end
17
25
  end
18
26
  end
@@ -39,7 +39,7 @@ RSpec.shared_examples 'a Valkyrie::StorageAdapter' do
39
39
  # WebMock prevents the request from using send_request_with_body_stream as it can do IRL
40
40
  WebMock.disable!
41
41
  allow(storage_adapter).to receive(:file_mover).and_return(FileUtils.method(:cp))
42
- File.open(Valkyrie::Engine.root.join("spec", "fixtures", "files", "tn_example.jpg")) do |io_file|
42
+ File.open(Valkyrie.root_path.join("spec", "fixtures", "files", "tn_example.jpg")) do |io_file|
43
43
  sha1 = Digest::SHA1.file(io_file).to_s
44
44
 
45
45
  resource = Valkyrie::Specs::CustomResource.new(id: SecureRandom.uuid)
@@ -25,12 +25,13 @@ module Valkyrie
25
25
 
26
26
  # Find the adapter associated with the provided short name
27
27
  # @param short_name [Symbol]
28
- # @return [Valkyrie::StorageAdapter]
28
+ # @return [Object] the storage adapter
29
29
  # @raise Valkyrie::StorageAdapter::AdapterNotFoundError when we are unable to find the named adapter
30
30
  def find(short_name)
31
31
  storage_adapters.fetch(short_name)
32
32
  rescue KeyError
33
- raise "Unable to find #{self} with short_name of #{short_name.inspect}. Registered adapters are #{storage_adapters.keys.inspect}"
33
+ raise AdapterNotFoundError, "Unable to find #{self} with short_name of #{short_name.inspect}. " \
34
+ "Registered adapters are #{storage_adapters.keys.inspect}"
34
35
  end
35
36
 
36
37
  # Search through all registered storage adapters until it finds one that
@@ -53,7 +54,8 @@ module Valkyrie
53
54
 
54
55
  # Return the registered storage adapter which handles the given ID.
55
56
  # @param id [Valkyrie::ID]
56
- # @return [Valkyrie::StorageAdapter]
57
+ # @return [Object] the storage adapter
58
+ # @raise [Valkyrie::StorageAdapter::AdapterNotFoundError]
57
59
  def adapter_for(id:)
58
60
  handler = storage_adapters.values.find do |storage_adapter|
59
61
  storage_adapter.handles?(id: id)
@@ -74,7 +76,12 @@ module Valkyrie
74
76
  end
75
77
 
76
78
  def disk_path
77
- Pathname.new(io.path)
79
+ path = Pathname.new(io.path)
80
+ if block_given?
81
+ yield path
82
+ else
83
+ path
84
+ end
78
85
  end
79
86
 
80
87
  # @param digests [Array<Digest>]
@@ -89,7 +96,7 @@ module Valkyrie
89
96
  end
90
97
 
91
98
  # @param size [Integer]
92
- # @param digests [Array<Digest>]
99
+ # @param digests [Hash<String, String>] map of digest algorithm names to digest values.
93
100
  # @return [Boolean]
94
101
  def valid?(size: nil, digests:)
95
102
  return false if size && io.size.to_i != size.to_i
@@ -102,17 +109,34 @@ module Valkyrie
102
109
 
103
110
  class StreamFile < File
104
111
  def disk_path
105
- Pathname.new(tmp_file.path)
112
+ path = Pathname.new(tmp_file.path)
113
+ if block_given?
114
+ yield path
115
+ clean_tmp_file
116
+ else
117
+ path
118
+ end
119
+ end
120
+
121
+ def close
122
+ super
123
+ clean_tmp_file
106
124
  end
107
125
 
108
126
  private
109
127
 
128
+ def clean_tmp_file
129
+ return unless @tmp_file
130
+ ::File.delete(tmp_file.path)
131
+ @tmp_file = nil
132
+ end
133
+
110
134
  def tmp_file_name
111
135
  id.to_s.tr(':/', '__')
112
136
  end
113
137
 
114
138
  def tmp_file_path
115
- ::File.join(Dir.tmpdir, tmp_file_name)
139
+ ::File.join(Dir.tmpdir, "#{SecureRandom.uuid}-#{tmp_file_name}")
116
140
  end
117
141
 
118
142
  def tmp_file
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Valkyrie
3
- VERSION = "3.1.4"
3
+ VERSION = "3.2.0"
4
4
  end
data/lib/valkyrie.rb CHANGED
@@ -60,6 +60,14 @@ module Valkyrie
60
60
  end
61
61
  end
62
62
 
63
+ def root_path
64
+ if Valkyrie.const_defined?(:Engine)
65
+ Valkyrie::Engine.root
66
+ else
67
+ Pathname.new(__dir__).dirname
68
+ end
69
+ end
70
+
63
71
  # @return [Valkyrie::Logging]
64
72
  def logger
65
73
  @logger ||= Valkyrie::Logging.new(logger: Logger.new(STDOUT))
@@ -123,5 +131,5 @@ module Valkyrie
123
131
  end
124
132
  end
125
133
 
126
- module_function :config, :logger, :logger=, :config_root_path, :environment, :config_file, :config_hash
134
+ module_function :config, :logger, :logger=, :config_root_path, :environment, :config_file, :config_hash, :root_path
127
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valkyrie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trey Pendragon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -582,7 +582,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
582
582
  - !ruby/object:Gem::Version
583
583
  version: '0'
584
584
  requirements: []
585
- rubygems_version: 3.3.7
585
+ rubygems_version: 3.1.6
586
586
  signing_key:
587
587
  specification_version: 4
588
588
  summary: An ORM using the Data Mapper pattern, specifically built to solve Digital