Class: SolidusFeeds::Publishers::S3
- Inherits:
-
Object
- Object
- SolidusFeeds::Publishers::S3
- Defined in:
- lib/solidus_feeds/publishers/s3.rb
Constant Summary collapse
- NoContentError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#object_key ⇒ Object
readonly
Returns the value of attribute object_key.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(object_key:, bucket:, client: Aws::S3::Client.new) ⇒ S3
constructor
A new instance of S3.
Constructor Details
#initialize(object_key:, bucket:, client: Aws::S3::Client.new) ⇒ S3
Returns a new instance of S3.
12 13 14 15 16 |
# File 'lib/solidus_feeds/publishers/s3.rb', line 12 def initialize(object_key:, bucket:, client: Aws::S3::Client.new) @object_key = object_key @bucket = bucket @resource = Aws::S3::Resource.new(client: client) end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
8 9 10 |
# File 'lib/solidus_feeds/publishers/s3.rb', line 8 def bucket @bucket end |
#object_key ⇒ Object (readonly)
Returns the value of attribute object_key.
8 9 10 |
# File 'lib/solidus_feeds/publishers/s3.rb', line 8 def object_key @object_key end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
8 9 10 |
# File 'lib/solidus_feeds/publishers/s3.rb', line 8 def resource @resource end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/solidus_feeds/publishers/s3.rb', line 18 def call Tempfile.create(object_key) do |io| yield io io.rewind raise NoContentError, "no content was generated" if io.eof? object = resource.bucket(bucket).object(object_key) object.put(body: io, acl: 'public-read') end end |