Class: S3Archive::S3FileSynchronizer
- Inherits:
-
Object
- Object
- S3Archive::S3FileSynchronizer
- Includes:
- Logging
- Defined in:
- lib/s3archive/s3_file_synchronizer.rb
Instance Attribute Summary collapse
-
#local_file ⇒ Object
readonly
Returns the value of attribute local_file.
-
#s3_file ⇒ Object
readonly
Returns the value of attribute s3_file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(local_file, s3_file) ⇒ S3FileSynchronizer
constructor
A new instance of S3FileSynchronizer.
- #run ⇒ Object
Methods included from Logging
Constructor Details
#initialize(local_file, s3_file) ⇒ S3FileSynchronizer
Returns a new instance of S3FileSynchronizer.
10 11 12 13 |
# File 'lib/s3archive/s3_file_synchronizer.rb', line 10 def initialize(local_file, s3_file) @local_file = local_file @s3_file = s3_file end |
Instance Attribute Details
#local_file ⇒ Object (readonly)
Returns the value of attribute local_file.
9 10 11 |
# File 'lib/s3archive/s3_file_synchronizer.rb', line 9 def local_file @local_file end |
#s3_file ⇒ Object (readonly)
Returns the value of attribute s3_file.
9 10 11 |
# File 'lib/s3archive/s3_file_synchronizer.rb', line 9 def s3_file @s3_file end |
Class Method Details
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/s3archive/s3_file_synchronizer.rb', line 15 def run if s3_file.exists? if s3_file.md5_hex == local_file.md5_hex logger.info("'#{s3_file}' already exists and has correct checksum") nil else new_s3_file = S3File.new(s3_file.bucket, "#{s3_file.key}.#{local_file.md5_hex}") logger.error("'#{s3_file}' already exists and has wrong checksum. Uploading to '#{new_s3_file}'.") new_s3_file.put(local_file) end else s3_file.put(local_file) end end |