Class: Microstatic::S3Deployer
- Inherits:
-
Object
- Object
- Microstatic::S3Deployer
- Includes:
- UsesFog
- Defined in:
- lib/microstatic/s3_deployer.rb
Overview
The following is based on code generously shared by Giles Alexander (@gga)
Instance Attribute Summary collapse
-
#file_list ⇒ Object
readonly
TODO: don’t expose this directly.
Instance Method Summary collapse
-
#initialize(local_dir, bucket, aws_creds) ⇒ S3Deployer
constructor
A new instance of S3Deployer.
- #upload ⇒ Object
- #upload_file(file) ⇒ Object
Methods included from UsesFog
#check_and_store_aws_creds, #connection, #dns
Constructor Details
#initialize(local_dir, bucket, aws_creds) ⇒ S3Deployer
Returns a new instance of S3Deployer.
14 15 16 17 18 19 20 |
# File 'lib/microstatic/s3_deployer.rb', line 14 def initialize( local_dir, bucket, aws_creds ) check_and_store_aws_creds(aws_creds) @local_dir = Pathname.new(local_dir) @file_list = ::Rake::FileList.new( (@local_dir+"**/*").to_s ) @bucket = bucket end |
Instance Attribute Details
#file_list ⇒ Object (readonly)
TODO: don’t expose this directly
12 13 14 |
# File 'lib/microstatic/s3_deployer.rb', line 12 def file_list @file_list end |
Instance Method Details
#upload ⇒ Object
22 23 24 25 26 27 |
# File 'lib/microstatic/s3_deployer.rb', line 22 def upload @file_list.each do |entry| entry = Pathname.new(entry) upload_file(entry) unless entry.directory? end end |
#upload_file(file) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/microstatic/s3_deployer.rb', line 29 def upload_file( file ) s3_key = file.relative_path_from(@local_dir).to_s begin s3_object = connection.head_object(@bucket,s3_key) rescue Excon::Errors::NotFound s3_object = false end if !s3_object log_action('CREATE', s3_key) put_file( s3_key, file ) else s3_md5 = s3_object.headers['ETag'].sub(/"(.*)"/,'\1') local_md5 = Digest::MD5.hexdigest( file.read ) if( s3_md5 == local_md5 ) log_action('NO CHANGE', s3_key) else log_action('UPDATE', s3_key) put_file( s3_key, file ) end end end |