valkyrie 3.1.5 → 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: 4efad2e357e3b34a76b6e6b9c3362d48c571388b7ac8979bbf6e38a1047bf8ce
4
- data.tar.gz: 40cd0c353e5f04e9eaffa22fb0ea3f13eedf97033b0ce17e6cfa3746ca79fcc9
3
+ metadata.gz: 7439f8be7099e4b54998826abda9222d07226ff7a54fdb868f2ab7d99596fd56
4
+ data.tar.gz: 866c57941b2e2604a8d7bd8b013e0b31c07dd909404733cfb7043c61412389ad
5
5
  SHA512:
6
- metadata.gz: 418d8f6390418de4b76230db5f0a980b79a6d6109250d72a40480b2ca1f5e59fab6ca8ece7334ed6e2a29e81be7b488aeb41cbaa6ec94814752e5d4da00c4b1b
7
- data.tar.gz: 62e9f00d29a7d3d16ad8d9211925618b13b995a09f24c7cb72dd94fa68b124dc1686a9fc333a21bc305e2118e0b3015282a871165fe5de04a67b941d56cfd85d
6
+ metadata.gz: 89d1857a2f40c0d8c32c6a31a9ff1247e9b8c32aa84e917c77c3d89e6a0cb52c7548802852914ddcf11d9805f3cf0b6784331f937cf9004b18e63ecb27449971
7
+ data.tar.gz: 5b143107a9ca53b86c83c5ba884635fb869919a7641c1373324193f9ac918684557177cf2c2519f5d8eeb0420bd48404037da5fb46c84d5a17bda0e4381b72f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
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
+
1
12
  # v3.1.5 2024-04-10
2
13
 
3
14
  ## 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
@@ -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.5"
3
+ VERSION = "3.2.0"
4
4
  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.5
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-04-10 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