Class: BucketSyncService

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_one_click_staging/bucket_sync_service.rb

Constant Summary collapse

DEFAULT_ACL =
:public_read

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from_credentials, to_credentials) ⇒ BucketSyncService

from_credentials and to_credentials are both hashes with these keys:

* :aws_access_key_id
* :aws_secret_access_key
* :bucket


15
16
17
18
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 15

def initialize(from_credentials, to_credentials)
  @from_bucket = bucket_from_credentials(from_credentials)
  @to_bucket   = bucket_from_credentials(to_credentials)
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



7
8
9
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 7

def debug
  @debug
end

#from_bucketObject (readonly)

Returns the value of attribute from_bucket.



6
7
8
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 6

def from_bucket
  @from_bucket
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 6

def logger
  @logger
end

#to_bucketObject (readonly)

Returns the value of attribute to_bucket.



6
7
8
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 6

def to_bucket
  @to_bucket
end

Instance Method Details

#perform(output = STDOUT) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 20

def perform(output=STDOUT)
  object_counts = {sync:0, skip:0}
  create_logger(output)

  logger.info "Starting sync."
  from_bucket.objects.each do |object|
    if object_needs_syncing?(object)
      sync(object)
      object_counts[:sync] += 1
    else
      logger.debug "Skipped #{pp object}"
      object_counts[:skip] += 1
    end
  end
  logger.info "Done. Synced #{object_counts[:sync]}, " +
    "skipped #{object_counts[:skip]}."
end