Class: RadiantAssetsExtension::S3Store

Inherits:
Dragonfly::DataStorage::S3DataStore
  • Object
show all
Defined in:
lib/radiant-assets-extension/s3_store.rb

Overview

Subclass that allows connecting to S3 regions other than US-Standard

Constant Summary collapse

DEFAULT_BUCKET_NAME =
'radiant-assets-extension'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ S3Store

Returns a new instance of S3Store.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/radiant-assets-extension/s3_store.rb', line 21

def initialize(opts={})
  # HACK: AWS::S3 doesn't support S3 international regions properly
  # https://github.com/marcel/aws-s3/issues#issue/4/comment/411302
  # we monkey-patch the default host
  AWS::S3::DEFAULT_HOST.replace Radiant::Config['s3.host'] || self.class.s3_region_hosts['us-east-1']
  super({
    :bucket_name => Radiant::Config['s3.bucket'] || DEFAULT_BUCKET_NAME,
    :access_key_id => Radiant::Config['s3.key'],
    :secret_access_key => Radiant::Config['s3.secret']
  }.merge(opts))
end

Class Method Details

.enabled?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/radiant-assets-extension/s3_store.rb', line 6

def self.enabled?
  Radiant::Config['assets.storage'] && Radiant::Config['assets.storage'] == 's3'
end

.region_hostsObject



10
11
12
13
14
15
16
17
# File 'lib/radiant-assets-extension/s3_store.rb', line 10

def self.region_hosts
  {
    'us-east-1' => 	's3.amazonaws.com',
    'us-west-1' => 's3-us-west-1.amazonaws.com',
    'eu-west-1' => 's3-eu-west-1.amazonaws.com',
    'ap-southeast-1' => 's3-ap-southeast-1.amazonaws.com'
  }
end

Instance Method Details

#connect!Object



33
34
35
36
37
38
39
# File 'lib/radiant-assets-extension/s3_store.rb', line 33

def connect!
  AWS::S3::Base.establish_connection!(
    :server => "#{bucket_name}.s3.amazonaws.com",
    :access_key_id => access_key_id,
    :secret_access_key => secret_access_key
  )
end