Class: ActiveAdmin::AsyncExporter::Services::AwsS3Service

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/async_exporter/services/aws_s3_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ AwsS3Service

Returns a new instance of AwsS3Service.



9
10
11
12
13
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 9

def initialize(file)
  @file = file
  @s3 = Aws::S3::Resource.new
  @bucket = s3.bucket(ActiveAdmin::AsyncExporter.config.aws_bucket_name)
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



7
8
9
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 7

def bucket
  @bucket
end

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 7

def file
  @file
end

#objectObject

Returns the value of attribute object.



7
8
9
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 7

def object
  @object
end

#s3Object

Returns the value of attribute s3.



7
8
9
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 7

def s3
  @s3
end

Instance Method Details

#deleteObject



25
26
27
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 25

def delete
  bucket.delete_objects({ delete: { objects: [{ key: filename }] } })
end

#storeObject



15
16
17
18
19
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 15

def store
  @object = bucket.object(filename)
  object.upload_file(Pathname.new(file[:path]), { acl: 'public-read' })
  self
end

#urlObject



21
22
23
# File 'lib/active_admin/async_exporter/services/aws_s3_service.rb', line 21

def url
  object.public_url.to_s
end