Class: Guidepost::Storage::S3
- Inherits:
-
Object
- Object
- Guidepost::Storage::S3
- Defined in:
- lib/guidepost/storage/s3.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ S3
constructor
A new instance of S3.
- #upload_file(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ S3
Returns a new instance of S3.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/guidepost/storage/s3.rb', line 6 def initialize(={}) @project_name = [:project_name] raise "Guidepost::Storage::S3 initializer is missing a project_name" if @project_name.nil? @project_name.upcase! @s3_client = Aws::S3::Resource.new( credentials: Aws::Credentials.new(ENV["#{@project_name}_GUIDEPOST_AWS_ACCESS_KEY_ID"], ENV["#{@project_name}_GUIDEPOST_AWS_SECRET_ACCESS_KEY"]), region: ENV["#{@project_name}_GUIDEPOST_AWS_REGION"] || "us-east-1" ) end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
4 5 6 |
# File 'lib/guidepost/storage/s3.rb', line 4 def project_name @project_name end |
Instance Method Details
#upload_file(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/guidepost/storage/s3.rb', line 19 def upload_file(={}) path = .fetch(:path, nil) string_content = .fetch(:string_content, "") acl = .fetch(:acl, "private") = .fetch(:metadata, nil) bucket_name = ENV["#{self.project_name}_GUIDEPOST_S3_BUCKET_NAME"] storage_class = ENV["#{self.project_name}_GUIDEPOST_S3_STORAGE_CLASS"] || "STANDARD_IA" return false if path.nil? begin obj = @s3_client.bucket(bucket_name).object(path) result = obj.put({ body: string_content, acl: acl, storage_class: storage_class, metadata: , }) rescue Seahorse::Client::NetworkingError => e raise e if !Rails.env.test? return true end return !result.nil? end |