Module: LetterOpenerWebS3

Defined in:
lib/letter_opener_web_s3.rb,
lib/letter_opener_web_s3/version.rb

Defined Under Namespace

Modules: LetterExtension, MessageExtension Classes: S3ConfigError, S3CredentialsError

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.bucketObject

Raises:



46
47
48
49
50
51
52
53
54
# File 'lib/letter_opener_web_s3.rb', line 46

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

.configure {|_self| ... } ⇒ Object

Sets up an S3 backend

Yields:

  • (_self)

Yield Parameters:

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/letter_opener_web_s3.rb', line 31

def configure
  extensions = -> do
    LetterOpener::Message.send :include, LetterOpenerWebS3::MessageExtension
    LetterOpenerWeb::Letter.send :include, LetterOpenerWebS3::LetterExtension
  end

  if ActiveSupport.version.to_s.start_with?('4')
    ActionDispatch::Reloader.to_prepare { extensions.call }
  else
    ActiveSupport::Reloader.to_prepare { extensions.call }
  end

  yield self
end