Class: AssetID::S3
- Inherits:
-
Object
- Object
- AssetID::S3
- Defined in:
- lib/asset_id/backend/s3.rb
Class Method Summary collapse
- .connect_to_s3 ⇒ Object
- .s3_bucket ⇒ Object
- .s3_bucket_url ⇒ Object
- .s3_config ⇒ Object
- .s3_permissions ⇒ Object
- .s3_prefix ⇒ Object
- .upload(options = {}) ⇒ Object
Class Method Details
.connect_to_s3 ⇒ Object
10 11 12 13 14 15 |
# File 'lib/asset_id/backend/s3.rb', line 10 def self.connect_to_s3 AWS::S3::Base.establish_connection!( :access_key_id => s3_config['access_key_id'], :secret_access_key => s3_config['secret_access_key'] ) end |
.s3_bucket ⇒ Object
21 22 23 |
# File 'lib/asset_id/backend/s3.rb', line 21 def self.s3_bucket s3_config['bucket'] end |
.s3_bucket_url ⇒ Object
29 30 31 |
# File 'lib/asset_id/backend/s3.rb', line 29 def self.s3_bucket_url "http://#{s3_bucket}.s3.amazonaws.com" end |
.s3_config ⇒ Object
6 7 8 |
# File 'lib/asset_id/backend/s3.rb', line 6 def self.s3_config @@config ||= YAML.load_file(File.join(Rails.root, "config/asset_id.yml"))[Rails.env] rescue nil || {} end |
.s3_permissions ⇒ Object
17 18 19 |
# File 'lib/asset_id/backend/s3.rb', line 17 def self. :public_read end |
.s3_prefix ⇒ Object
25 26 27 |
# File 'lib/asset_id/backend/s3.rb', line 25 def self.s3_prefix s3_config['prefix'] || s3_bucket_url end |
.upload(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/asset_id/backend/s3.rb', line 33 def self.upload(={}) Asset.init(:debug => [:debug]) assets = Asset.find return if assets.empty? connect_to_s3 assets.each do |asset| puts "AssetID: #{asset.relative_path}" if [:debug] headers = { :content_type => asset.mime_type, :access => , }.merge(asset.cache_headers) asset.replace_css_images!(:prefix => s3_prefix) if asset.css? if asset.gzip_type? headers.merge!(asset.gzip_headers) asset.gzip! end if [:debug] puts " - Uploading: #{asset.fingerprint} [#{asset.data.size} bytes]" puts " - Headers: #{headers.inspect}" end unless [:dry_run] res = AWS::S3::S3Object.store( asset.fingerprint, asset.data, s3_bucket, headers ) puts " - Response: #{res.inspect}" if [:debug] end end Cache.save! unless [:dry_run] end |