Sha256: a7e49d827b62a8d166acae047de9b81f95426103516ecb2a93785116e986b51f
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
require 'active_support' require 'aws-sdk' require 'letter_opener' require 'letter_opener_web' require "letter_opener_web_s3/version" require "letter_opener_web_s3/message_extension" require "letter_opener_web_s3/letter_extension" module LetterOpenerWebS3 mattr_accessor :s3_config mattr_accessor :domain # @api private class S3ConfigError < StandardError; end # @api private class S3CredentialsError < StandardError def message "Credentials not found" end end class << self # Sets up an S3 backend # # @s3_config [String] region The AWS region to connect to # @s3_config [String] bucket_name The name of the bucket where files will be stored # @s3_config [String] access_key_id Access key ID # @s3_config [String] secret_access_key Secret access key # @domain [String] Domain to assets link # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/Core/Configuration.html # @see http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3.html def configure yield self end def bucket raise S3ConfigError if !s3_config.is_a?(Hash) || (s3_config.keys & [:region, :bucket_name, :access_key_id, :secret_access_key]).size != 4 return @bucket if @bucket @s3 = Aws::S3::Resource.new s3_config.slice(:region, :access_key_id, :secret_access_key) credentials = @s3.client.config.credentials raise S3CredentialsError unless credentials @bucket = @s3.bucket s3_config[:bucket_name] end end end ActionDispatch::Reloader.to_prepare(prepend: true) do LetterOpener::Message.send :include, LetterOpenerWebS3::MessageExtension LetterOpenerWeb::Letter.send :include, LetterOpenerWebS3::LetterExtension end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
letter_opener_web_s3-0.1.0 | lib/letter_opener_web_s3.rb |