Class: FasterS3Url::Shrine::Storage
- Inherits:
-
Shrine::Storage::S3
- Object
- Shrine::Storage::S3
- FasterS3Url::Shrine::Storage
- Defined in:
- lib/faster_s3_url/shrine/storage.rb
Overview
More or less a drop-in replacement for Shrine::Storage::S3 , that uses FasterS3Url faster S3 URL generation. shrinerb.com/docs/storage/s3
require 'faster_s3_url/storage/shrine'
s3 = FasterS3Url::Shrine::Storage.new(
bucket: "my-app", # required
region: "eu-west-1", # required
access_key_id: "abc",
secret_access_key: "xyz"
)
A couple incompatibilities with Shrine::Storage::S3, which I don’t expect to cause problems for anyone but if they do please let me know.
* we do not support the :signer option in initialier (why would you want to use that with this? Let me know)
* We support a `host` option on initializer, but do NOT support the `host` option on #url (I don't underestand
why it's per-call in the first place, do you need it to be?)
* You DO need to supply access_key_id and secret_access_key in initializer, they can not be automatically
looked up from AWS environmental chain. See README.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Storage
constructor
Same options as Shrine::Storage::S3, plus ‘host`.
- #object_key(id) ⇒ Object
-
#url(id, public: self.public, **options) ⇒ Object
unlike base Shrine::Storage::S3, does not support ‘host` here, do it in initializer instead.
Constructor Details
#initialize(**options) ⇒ Storage
Same options as Shrine::Storage::S3, plus ‘host`
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/faster_s3_url/shrine/storage.rb', line 33 def initialize(**) if [:signer] raise ArgumentError.new("#{self.class.name} does not support :signer option of Shrine::Storage::S3. Should it? Let us know.") end host = .delete(:host) @faster_s3_url_builder = FasterS3Url::Builder.new( bucket_name: [:bucket], access_key_id: [:access_key_id], secret_access_key: [:secret_access_key], region: [:region], host: host) super(**) end |
Instance Method Details
#object_key(id) ⇒ Object
65 66 67 |
# File 'lib/faster_s3_url/shrine/storage.rb', line 65 def object_key(id) [*prefix, id].join("/") end |
#url(id, public: self.public, **options) ⇒ Object
unlike base Shrine::Storage::S3, does not support ‘host` here, do it in initializer instead. Is there a really use case for doing it here? If so let us know.
options are ignored when public mode, so you can send options the same for public or not, and not get an error on public for options only appropriate to presigned.
Otherwise, same options as Shrine::S3::Storage should be supported, please see docs there. shrinerb.com/docs/storage/s3
59 60 61 |
# File 'lib/faster_s3_url/shrine/storage.rb', line 59 def url(id, public: self.public, **) @faster_s3_url_builder.url(object_key(id), public: public, **) end |