Class: Embarista::S3sync
- Inherits:
-
Object
- Object
- Embarista::S3sync
- Defined in:
- lib/embarista/s3sync.rb
Instance Attribute Summary collapse
-
#local_manifest_path ⇒ Object
readonly
Returns the value of attribute local_manifest_path.
-
#remote_manifest_path ⇒ Object
readonly
Returns the value of attribute remote_manifest_path.
-
#s3 ⇒ Object
readonly
Returns the value of attribute s3.
Class Method Summary collapse
Instance Method Summary collapse
- #build_delta_manifest ⇒ Object
-
#initialize(root, opts = {}) ⇒ S3sync
constructor
A new instance of S3sync.
- #local_manifest ⇒ Object
- #local_manifest_file_name ⇒ Object
- #remote_manifest ⇒ Object
- #remote_manifest_file_name ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize(root, opts = {}) ⇒ S3sync
Returns a new instance of S3sync.
7 8 9 10 11 12 |
# File 'lib/embarista/s3sync.rb', line 7 def initialize(root, opts={}) @local_manifest_path = opts[:local_manifest_path] @remote_manifest_path = opts[:remote_manifest_path] @root = Pathname.new(root). @s3 = S3.new(opts.fetch(:bucket_name), root: root) end |
Instance Attribute Details
#local_manifest_path ⇒ Object (readonly)
Returns the value of attribute local_manifest_path.
5 6 7 |
# File 'lib/embarista/s3sync.rb', line 5 def local_manifest_path @local_manifest_path end |
#remote_manifest_path ⇒ Object (readonly)
Returns the value of attribute remote_manifest_path.
5 6 7 |
# File 'lib/embarista/s3sync.rb', line 5 def remote_manifest_path @remote_manifest_path end |
#s3 ⇒ Object (readonly)
Returns the value of attribute s3.
5 6 7 |
# File 'lib/embarista/s3sync.rb', line 5 def s3 @s3 end |
Class Method Details
Instance Method Details
#build_delta_manifest ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/embarista/s3sync.rb', line 43 def build_delta_manifest return local_manifest unless remote_manifest new_manifest_values = local_manifest.values - remote_manifest.values local_manifest.select {|key, value| new_manifest_values.include? value } end |
#local_manifest ⇒ Object
62 63 64 |
# File 'lib/embarista/s3sync.rb', line 62 def local_manifest @local_manifest ||= YAML.load_file(@root + local_manifest_path) end |
#local_manifest_file_name ⇒ Object
39 40 41 |
# File 'lib/embarista/s3sync.rb', line 39 def local_manifest_file_name File.basename(local_manifest_path) end |
#remote_manifest ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/embarista/s3sync.rb', line 51 def remote_manifest @remote_manifest ||= begin if remote_manifest = s3.read(remote_manifest_file_name) YAML.load(remote_manifest) else puts 'no remote existing manifest, uploading everything' nil end end end |
#remote_manifest_file_name ⇒ Object
35 36 37 |
# File 'lib/embarista/s3sync.rb', line 35 def remote_manifest_file_name File.basename(remote_manifest_path) end |
#sync ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/embarista/s3sync.rb', line 18 def sync delta_manifest = build_delta_manifest if delta_manifest.empty? puts 'everything is up to date' return end delta_manifest.values.each do |file_name| file_name[0] = '' s3.store(file_name) end s3.store(remote_manifest_file_name, local_manifest_path) s3.store(local_manifest_file_name, local_manifest_path) end |