Module: Middleman::S3Sync
- Extended by:
- CachingPolicy, Status
- Defined in:
- lib/middleman/s3_sync.rb,
lib/middleman/s3_sync/status.rb,
lib/middleman/s3_sync/options.rb,
lib/middleman/s3_sync/version.rb,
lib/middleman/s3_sync/resource.rb,
lib/middleman/s3_sync/cloudfront.rb,
lib/middleman/s3_sync/caching_policy.rb
Defined Under Namespace
Modules: CachingPolicy, CloudFront, Status Classes: BrowserCachePolicy, Options, Resource
Constant Summary collapse
- THREADS_COUNT =
8
- VERSION =
"4.6.1"
- @@bucket_lock =
Mutex.new
- @@bucket_files_lock =
Mutex.new
Class Attribute Summary collapse
-
.app ⇒ Object
Returns the value of attribute app.
-
.invalidation_paths ⇒ Object
Track paths that were changed during sync for CloudFront invalidation.
-
.mm_resources ⇒ Object
Returns the value of attribute mm_resources.
-
.s3_sync_options ⇒ Object
Returns the value of attribute s3_sync_options.
Class Method Summary collapse
- .add_invalidation_path(path) ⇒ Object
- .add_local_resource(mm_resource) ⇒ Object
- .bucket ⇒ Object
- .content_types ⇒ Object
- .remote_only_paths ⇒ Object
- .sync ⇒ Object
Methods included from CachingPolicy
add_caching_policy, caching_policies, caching_policy_for, default_caching_policy
Methods included from Status
Class Attribute Details
.app ⇒ Object
Returns the value of attribute app.
26 27 28 |
# File 'lib/middleman/s3_sync.rb', line 26 def app @app end |
.invalidation_paths ⇒ Object
Track paths that were changed during sync for CloudFront invalidation
31 32 33 |
# File 'lib/middleman/s3_sync.rb', line 31 def invalidation_paths @invalidation_paths end |
.mm_resources ⇒ Object
Returns the value of attribute mm_resources.
25 26 27 |
# File 'lib/middleman/s3_sync.rb', line 25 def mm_resources @mm_resources end |
.s3_sync_options ⇒ Object
Returns the value of attribute s3_sync_options.
24 25 26 |
# File 'lib/middleman/s3_sync.rb', line 24 def @s3_sync_options end |
Class Method Details
.add_invalidation_path(path) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/middleman/s3_sync.rb', line 79 def add_invalidation_path(path) @invalidation_paths ||= [] # Normalize path for CloudFront (ensure it starts with /) normalized_path = path.start_with?('/') ? path : "/#{path}" @invalidation_paths << normalized_path unless @invalidation_paths.include?(normalized_path) end |
.add_local_resource(mm_resource) ⇒ Object
75 76 77 |
# File 'lib/middleman/s3_sync.rb', line 75 def add_local_resource(mm_resource) s3_sync_resources[mm_resource.destination_path] = S3Sync::Resource.new(mm_resource, remote_resource_for_path(mm_resource.destination_path)).tap(&:status) end |
.bucket ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/middleman/s3_sync.rb', line 65 def bucket @@bucket_lock.synchronize do @bucket ||= begin bucket = s3_resource.bucket(.bucket) raise "Bucket #{.bucket} doesn't exist!" unless bucket.exists? bucket end end end |
.content_types ⇒ Object
94 95 96 |
# File 'lib/middleman/s3_sync.rb', line 94 def content_types @content_types || {} end |
.remote_only_paths ⇒ Object
86 87 88 |
# File 'lib/middleman/s3_sync.rb', line 86 def remote_only_paths paths - s3_sync_resources.keys end |
.sync ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/middleman/s3_sync.rb', line 33 def sync() @app ||= ::Middleman::Application.new @invalidation_paths = [] say_status "Let's see if there's work to be done..." unless work_to_be_done? say_status "All S3 files are up to date." # Still run CloudFront invalidation if requested for all paths if .cloudfront_invalidate && .cloudfront_invalidate_all CloudFront.invalidate([], ) end return end say_status "Ready to apply updates to #{.bucket}." update_bucket_versioning update_bucket_website ignore_resources create_resources update_resources delete_resources # Invalidate CloudFront cache if requested if .cloudfront_invalidate CloudFront.invalidate(@invalidation_paths, ) end end |