Class: Configuration::S3Store

Inherits:
S3SourceStoreBase show all
Defined in:
lib/httpimagestore/configuration/s3.rb

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from S3SourceStoreBase

#client, #initialize, #object, #url

Methods inherited from SourceStoreBase

#initialize

Methods inherited from HandlerStatement

#config_local, #initialize, #path_template

Constructor Details

This class inherits a constructor from Configuration::S3SourceStoreBase

Class Method Details

.match(node) ⇒ Object



416
417
418
# File 'lib/httpimagestore/configuration/s3.rb', line 416

def self.match(node)
	node.name == 'store_s3'
end

.parse(configuration, node) ⇒ Object



420
421
422
# File 'lib/httpimagestore/configuration/s3.rb', line 420

def self.parse(configuration, node)
	configuration.stores << super
end

Instance Method Details

#realize(request_state) ⇒ Object



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/httpimagestore/configuration/s3.rb', line 424

def realize(request_state)
	get_named_image_for_storage(request_state) do |image_name, image, rendered_path|
		acl = @public_access ?  :public_read : :private

		log.info "storing '#{image_name}' image in S3 '#{@bucket}' bucket under '#{rendered_path}' key with #{acl} access"

		object(rendered_path) do |object|
			image.mime_type or log.warn "storing '#{image_name}' in S3 '#{@bucket}' bucket under '#{rendered_path}' key with unknown mime type"

			options = {}
			options[:single_request] = true
			options[:content_type] = image.mime_type if image.mime_type
			options[:acl] = acl
			options[:cache_control] = @cache_control if @cache_control

			object.write(image.data, options)
			S3SourceStoreBase.stats.incr_total_s3_store
			S3SourceStoreBase.stats.incr_total_s3_store_bytes(image.data.bytesize)

			image.store_url = url(object)
		end
	end
end