valkyrie-shrine 0.1.0 → 0.5.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: 43acefce16f29dafdd2627b82dbb79baa25e11e8b2503f33b1a49b8e4684fa81
4
- data.tar.gz: 8cdd2a2fb849326f7945f9a4c20cf064c755d4bb1aac5371119d3a9db90ac9e3
3
+ metadata.gz: d5d7dc948b6f87906f3d62207c2d9a3642ee52b34ddabebdefbe5dcde3eb47f4
4
+ data.tar.gz: acc1806a446bfd8e8c4e1f16a9b2e9a475ab3309296f8ba44a0cb6e3b255494c
5
5
  SHA512:
6
- metadata.gz: f7b3a2a459b419e0e046be241b1e5d32b063de7704e211672a7823430d16c47d22cf72af8f2edc43c6023d14f49b60dff781144486e2d06ef9be637ebc02b557
7
- data.tar.gz: 4768279b6f1ef8b1872cefd71e0114397a2a9029d5978dc196ce43acdb97ff4dfdbdda062f5854ed92dbeb553e182564ed91b22ca60af225e7c04a88bd725d4d
6
+ metadata.gz: 9cf334edc64829d8ae960e8e35037cdce590edcfc08b6f29fcbb0464337571bd015b938d38a7d0e0b7f77d7f2474a695a2f829c22884c91362ecba3be583bff7
7
+ data.tar.gz: 96b16e3d76a6d670fbe1bd46393b8ba6ad0bdd6b79678c6100f305c5b5347c2a91a02679d21ebe22914e1e3d992094512d7821e142b3d539c78b439719036f98
data/README.md CHANGED
@@ -21,8 +21,8 @@ Follow the Valkyrie [README](https://github.com/samvera-labs/valkyrie) to get a
21
21
  # config/initializers/valkyrie.rb
22
22
  require 'shrine/storage/s3'
23
23
  require 'shrine/storage/file_system'
24
- require 'valkyrie/storage/shrine/s3_checksum'
25
- require 'valkyrie/storage/shrine/file_system_checksum'
24
+ require 'valkyrie/storage/shrine/checksum/s3'
25
+ require 'valkyrie/storage/shrine/checksum/file_system'
26
26
 
27
27
  Shrine.storages = {
28
28
  file: Shrine::Storage::FileSystem.new("public", prefix: "uploads"),
@@ -38,6 +38,8 @@ Follow the Valkyrie [README](https://github.com/samvera-labs/valkyrie) to get a
38
38
  )
39
39
  ```
40
40
 
41
+ Then proceed to configure your application following the [Valkyrie documentation](https://github.com/samvera-labs/valkyrie#sample-configuration-configvalkyrieyml)
42
+
41
43
  ## Development
42
44
 
43
45
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -46,4 +48,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
46
48
 
47
49
  ## Contributing
48
50
 
49
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/valkyrie-shrine.
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/samvera-labs/valkyrie-shrine.
data/circle.yml CHANGED
@@ -2,7 +2,7 @@ version: 2
2
2
  jobs:
3
3
  build:
4
4
  docker:
5
- - image: circleci/ruby:2.6.1
5
+ - image: cimg/ruby:2.6.1
6
6
  environment:
7
7
  BUNDLER_VERSION: 2.0.1
8
8
  steps:
@@ -26,4 +26,4 @@ jobs:
26
26
  command: bundle exec rubocop
27
27
  - run:
28
28
  name: Run Specs
29
- command: bundle exec rspec spec
29
+ command: bundle exec rspec spec
@@ -16,7 +16,8 @@ module Valkyrie
16
16
  end
17
17
 
18
18
  def calculate_checksum(result)
19
- result.io.data[:object].data.etag.delete('"')
19
+ result.io.data[:object]&.data&.etag&.delete('"') ||
20
+ checksum_for(result.io)
20
21
  end
21
22
 
22
23
  def checksum_for(io)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Valkyrie
4
4
  module Shrine
5
- VERSION = "0.1.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
@@ -8,10 +8,43 @@ module Valkyrie
8
8
  class Shrine
9
9
  PROTOCOL = 'shrine://'
10
10
 
11
- attr_reader :shrine, :verifier
11
+ attr_reader :shrine, :verifier, :path_generator, :identifier_prefix
12
12
 
13
- def initialize(shrine_storage, verifier = nil)
13
+ class IDPathGenerator
14
+ def initialize(base_path: nil)
15
+ @base_path = base_path
16
+ end
17
+
18
+ def generate(resource:, file:, original_filename:)
19
+ resource.id.to_s
20
+ end
21
+ end
22
+
23
+ class DelayedDownload
24
+ attr_reader :shrine, :id
25
+ def initialize(shrine, id)
26
+ @shrine = shrine
27
+ @id = id
28
+ end
29
+
30
+ def file
31
+ @file ||= shrine.open(id)
32
+ end
33
+
34
+ def method_missing(meth_name, *args, &block)
35
+ return super unless file.respond_to?(meth_name)
36
+ file.send(meth_name, *args, &block)
37
+ end
38
+
39
+ def respond_to_missing?(meth_name, include_private = false)
40
+ file.respond_to?(meth_name) || super
41
+ end
42
+ end
43
+
44
+ def initialize(shrine_storage, verifier = nil, path_generator = IDPathGenerator, identifier_prefix: nil)
45
+ @path_generator = path_generator.new(base_path: "")
14
46
  @shrine = shrine_storage
47
+ @identifier_prefix = identifier_prefix
15
48
  if verifier.nil?
16
49
  try_to_find_verifier
17
50
  else
@@ -27,9 +60,12 @@ module Valkyrie
27
60
  # @raise Valkyrie::Shrine::IntegrityError if #verify_checksum is defined
28
61
  # on the shrine object and the file and result digests do not match
29
62
  def upload(file:, original_filename:, resource:, **upload_options)
30
- identifier = resource.id.to_s
63
+ # S3 adapter validates options, so we have to remove this one used in
64
+ # the shared specs.
65
+ upload_options.delete(:fake_upload_argument)
66
+ identifier = path_generator.generate(resource: resource, file: file, original_filename: original_filename).to_s
31
67
  shrine.upload(file, identifier, **upload_options)
32
- find_by(id: "#{PROTOCOL}#{identifier}").tap do |result|
68
+ find_by(id: "#{protocol_with_prefix}#{identifier}").tap do |result|
33
69
  if verifier
34
70
  raise Valkyrie::Shrine::IntegrityError unless verifier.verify_checksum(file, result)
35
71
  end
@@ -41,7 +77,8 @@ module Valkyrie
41
77
  # @return [Valkyrie::StorageAdapter::StreamFile]
42
78
  # @raise Valkyrie::StorageAdapter::FileNotFound if nothing is found
43
79
  def find_by(id:)
44
- Valkyrie::StorageAdapter::StreamFile.new(id: Valkyrie::ID.new(id.to_s), io: shrine.open(shrine_id_for(id)))
80
+ raise Valkyrie::StorageAdapter::FileNotFound unless shrine.exists?(shrine_id_for(id))
81
+ Valkyrie::StorageAdapter::StreamFile.new(id: Valkyrie::ID.new(id.to_s), io: DelayedDownload.new(shrine, shrine_id_for(id)))
45
82
  rescue Aws::S3::Errors::NoSuchKey
46
83
  raise Valkyrie::StorageAdapter::FileNotFound
47
84
  end
@@ -49,7 +86,7 @@ module Valkyrie
49
86
  # @param id [Valkyrie::ID]
50
87
  # @return [Boolean] true if this adapter can handle this type of identifier
51
88
  def handles?(id:)
52
- id.to_s.start_with?(PROTOCOL)
89
+ id.to_s.start_with?(protocol_with_prefix)
53
90
  end
54
91
 
55
92
  # Delete the file in S3 associated with the given identifier.
@@ -66,7 +103,11 @@ module Valkyrie
66
103
  end
67
104
 
68
105
  def shrine_id_for(id)
69
- id.to_s.sub(/^#{PROTOCOL}/, '')
106
+ id.to_s.sub(/^#{protocol_with_prefix}/, '')
107
+ end
108
+
109
+ def protocol_with_prefix
110
+ [identifier_prefix, PROTOCOL].compact.join("-")
70
111
  end
71
112
  end
72
113
  end
@@ -7,6 +7,7 @@ require 'valkyrie/shrine/version'
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'valkyrie-shrine'
9
9
  spec.version = Valkyrie::Shrine::VERSION
10
+ spec.license = 'Apache-2.0'
10
11
  spec.authors = ['Brendan Quinn']
11
12
  spec.email = ['brendan-quinn@northwestern.edu']
12
13
 
@@ -23,15 +24,16 @@ Gem::Specification.new do |spec|
23
24
  spec.require_paths = ['lib']
24
25
 
25
26
  spec.add_dependency 'aws-sdk-s3', '~> 1'
26
- spec.add_dependency 'shrine', '~> 2.0'
27
- spec.add_dependency 'valkyrie', '~> 2.0.0.RC3'
27
+ spec.add_dependency 'shrine', '>= 2.0', '< 4.0'
28
+ spec.add_dependency 'valkyrie', '> 1.0'
28
29
 
29
30
  spec.add_development_dependency 'bixby', '~> 2.0.0.pre.beta1'
30
31
  spec.add_development_dependency 'bundler', '~> 2.0'
31
- spec.add_development_dependency 'coveralls'
32
+ spec.add_development_dependency 'coveralls', '~> 0.8.3'
32
33
  spec.add_development_dependency 'pry'
33
34
  spec.add_development_dependency 'pry-byebug'
34
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '>= 12.3.3'
35
36
  spec.add_development_dependency 'rspec', '~> 3.0'
36
37
  spec.add_development_dependency 'simplecov'
38
+ spec.add_development_dependency 'actionpack'
37
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.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Quinn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-07 00:00:00.000000000 Z
11
+ date: 2021-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
@@ -28,30 +28,36 @@ dependencies:
28
28
  name: shrine
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '4.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '2.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: valkyrie
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
- - - "~>"
51
+ - - ">"
46
52
  - !ruby/object:Gem::Version
47
- version: 2.0.0.RC3
53
+ version: '1.0'
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - "~>"
58
+ - - ">"
53
59
  - !ruby/object:Gem::Version
54
- version: 2.0.0.RC3
60
+ version: '1.0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: bixby
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +90,16 @@ dependencies:
84
90
  name: coveralls
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - ">="
93
+ - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '0'
95
+ version: 0.8.3
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - ">="
100
+ - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '0'
102
+ version: 0.8.3
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: pry
99
105
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +132,16 @@ dependencies:
126
132
  name: rake
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
- - - "~>"
135
+ - - ">="
130
136
  - !ruby/object:Gem::Version
131
- version: '10.0'
137
+ version: 12.3.3
132
138
  type: :development
133
139
  prerelease: false
134
140
  version_requirements: !ruby/object:Gem::Requirement
135
141
  requirements:
136
- - - "~>"
142
+ - - ">="
137
143
  - !ruby/object:Gem::Version
138
- version: '10.0'
144
+ version: 12.3.3
139
145
  - !ruby/object:Gem::Dependency
140
146
  name: rspec
141
147
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +170,21 @@ dependencies:
164
170
  - - ">="
165
171
  - !ruby/object:Gem::Version
166
172
  version: '0'
167
- description:
173
+ - !ruby/object:Gem::Dependency
174
+ name: actionpack
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ description:
168
188
  email:
169
189
  - brendan-quinn@northwestern.edu
170
190
  executables: []
@@ -190,9 +210,10 @@ files:
190
210
  - lib/valkyrie/storage/shrine.rb
191
211
  - valkyrie-shrine.gemspec
192
212
  homepage: https://github.com/samvera-labs/valkyrie-shrine
193
- licenses: []
213
+ licenses:
214
+ - Apache-2.0
194
215
  metadata: {}
195
- post_install_message:
216
+ post_install_message:
196
217
  rdoc_options: []
197
218
  require_paths:
198
219
  - lib
@@ -207,8 +228,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
228
  - !ruby/object:Gem::Version
208
229
  version: '0'
209
230
  requirements: []
210
- rubygems_version: 3.0.2
211
- signing_key:
231
+ rubygems_version: 3.1.4
232
+ signing_key:
212
233
  specification_version: 4
213
234
  summary: Shrine storage adapter for Valkyrie
214
235
  test_files: []