Class: SolidusFeeds::Publishers::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_feeds/publishers/s3.rb

Constant Summary collapse

NoContentError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketObject (readonly)

Returns the value of attribute bucket.



8
9
10
# File 'lib/solidus_feeds/publishers/s3.rb', line 8

def bucket
  @bucket
end

#object_keyObject (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

#resourceObject (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

#callObject



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