valkyrie-shrine 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ff75a9dea7b1a3e920b1fa9152fad9e109414bb047afe1265111e3746e73671
4
- data.tar.gz: 5f913f31d5499c272974669d9a30b478a367545daee706bc5580031e4b551c9c
3
+ metadata.gz: aef24fabeacf6da3dce1036b01bbc5738921e79f205b38c067d67d5d62d623f4
4
+ data.tar.gz: 53e0b0ffd66e766c808c0a5ce1be1ba340f4fe4404806f4f0c0c909eb62d5fd1
5
5
  SHA512:
6
- metadata.gz: aff9fadbab0b342f8180114f0ea38d51a93f8935e491bb5b35b1185c186efd33a94748faacc8e0a36541723cd37891dd72068c702f2227669cb92b733ec57bc4
7
- data.tar.gz: cef14742ca6ea9edaa892fdb16636c4312f174781b7014632b8cc4b331036e8a01f3b31b92126fd381c0ee35d8394c1c957a7d172410336556a2f667096bfe7e
6
+ metadata.gz: 4573d6b6f1ba7e0e6bdd4dc03df7cf442f9c73e727498bd36c064d8ad75df56fe4d13fa9f159cd3dfa52150bf2eefc6f3a903afbd32acc9d47d9141152360b9f
7
+ data.tar.gz: f6e541e72d6b15fda6fb9611a7422eede93d33054450662954b0c5bbab970df03154038a954b6f54f5821421ab2fea84ea8dbf86b591ecf4b99a3dbe829f6740
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Valkyrie
4
4
  module Shrine
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -8,7 +8,7 @@ module Valkyrie
8
8
  class Shrine
9
9
  PROTOCOL = 'shrine://'
10
10
 
11
- attr_reader :shrine, :verifier, :path_generator
11
+ attr_reader :shrine, :verifier, :path_generator, :identifier_prefix
12
12
 
13
13
  class IDPathGenerator
14
14
  def initialize(base_path: nil)
@@ -20,9 +20,10 @@ module Valkyrie
20
20
  end
21
21
  end
22
22
 
23
- def initialize(shrine_storage, verifier = nil, path_generator = IDPathGenerator)
23
+ def initialize(shrine_storage, verifier = nil, path_generator = IDPathGenerator, identifier_prefix: nil)
24
24
  @path_generator = path_generator.new(base_path: "")
25
25
  @shrine = shrine_storage
26
+ @identifier_prefix = identifier_prefix
26
27
  if verifier.nil?
27
28
  try_to_find_verifier
28
29
  else
@@ -38,9 +39,12 @@ module Valkyrie
38
39
  # @raise Valkyrie::Shrine::IntegrityError if #verify_checksum is defined
39
40
  # on the shrine object and the file and result digests do not match
40
41
  def upload(file:, original_filename:, resource:, **upload_options)
42
+ # S3 adapter validates options, so we have to remove this one used in
43
+ # the shared specs.
44
+ upload_options.delete(:fake_upload_argument)
41
45
  identifier = path_generator.generate(resource: resource, file: file, original_filename: original_filename).to_s
42
46
  shrine.upload(file, identifier, **upload_options)
43
- find_by(id: "#{PROTOCOL}#{identifier}").tap do |result|
47
+ find_by(id: "#{protocol_with_prefix}#{identifier}").tap do |result|
44
48
  if verifier
45
49
  raise Valkyrie::Shrine::IntegrityError unless verifier.verify_checksum(file, result)
46
50
  end
@@ -52,6 +56,7 @@ module Valkyrie
52
56
  # @return [Valkyrie::StorageAdapter::StreamFile]
53
57
  # @raise Valkyrie::StorageAdapter::FileNotFound if nothing is found
54
58
  def find_by(id:)
59
+ raise Valkyrie::StorageAdapter::FileNotFound unless shrine.exists?(shrine_id_for(id))
55
60
  Valkyrie::StorageAdapter::StreamFile.new(id: Valkyrie::ID.new(id.to_s), io: shrine.open(shrine_id_for(id)))
56
61
  rescue Aws::S3::Errors::NoSuchKey
57
62
  raise Valkyrie::StorageAdapter::FileNotFound
@@ -60,7 +65,7 @@ module Valkyrie
60
65
  # @param id [Valkyrie::ID]
61
66
  # @return [Boolean] true if this adapter can handle this type of identifier
62
67
  def handles?(id:)
63
- id.to_s.start_with?(PROTOCOL)
68
+ id.to_s.start_with?(protocol_with_prefix)
64
69
  end
65
70
 
66
71
  # Delete the file in S3 associated with the given identifier.
@@ -77,7 +82,11 @@ module Valkyrie
77
82
  end
78
83
 
79
84
  def shrine_id_for(id)
80
- id.to_s.sub(/^#{PROTOCOL}/, '')
85
+ id.to_s.sub(/^#{protocol_with_prefix}/, '')
86
+ end
87
+
88
+ def protocol_with_prefix
89
+ [identifier_prefix, PROTOCOL].compact.join("-")
81
90
  end
82
91
  end
83
92
  end
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rake', '~> 10.0'
36
36
  spec.add_development_dependency 'rspec', '~> 3.0'
37
37
  spec.add_development_dependency 'simplecov'
38
+ spec.add_development_dependency 'actionpack'
38
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valkyrie-shrine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Quinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-04 00:00:00.000000000 Z
11
+ date: 2019-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: actionpack
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  description:
168
182
  email:
169
183
  - brendan-quinn@northwestern.edu
@@ -208,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
222
  - !ruby/object:Gem::Version
209
223
  version: '0'
210
224
  requirements: []
211
- rubygems_version: 3.0.3
225
+ rubygems_version: 3.0.1
212
226
  signing_key:
213
227
  specification_version: 4
214
228
  summary: Shrine storage adapter for Valkyrie