Module: Middleman::S3Sync

Extended by:
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/extension.rb

Defined Under Namespace

Modules: Helpers, Status Classes: Options, Resource

Constant Summary collapse

VERSION =
"3.0.47"
@@bucket_lock =
Mutex.new
@@bucket_files_lock =
Mutex.new

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Status

say_status

Class Attribute Details

.optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/middleman-s3_sync/extension.rb', line 7

def options
  @options
end

Class Method Details

.bucketObject



45
46
47
48
49
50
51
52
53
# File 'lib/middleman/s3_sync.rb', line 45

def bucket
  @@bucket_lock.synchronize do
    @bucket ||= begin
                  bucket = connection.directories.get(s3_sync_options.bucket, :prefix => s3_sync_options.prefix)
                  raise "Bucket #{s3_sync_options.bucket} doesn't exist!" unless bucket
                  bucket
                end
  end
end

.registered(app, options_hash = {}) {|options| ... } ⇒ Object Also known as: included

Yields:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/middleman-s3_sync/extension.rb', line 9

def registered(app, options_hash = {}, &block)
  options = Options.new
  yield options if block_given?

  @options = options

  app.send :include, Helpers

  app.define_hook :after_s3_sync

  app.after_configuration do |config|
    # Record the http_prefix if it is set. We will need it while setting
    # the options to detect whether it is set and adjust the prefix value
    # accordingly
    options.http_prefix = app.respond_to? :http_prefix ? app.http_prefix : nil

    # Define the after_build step after during configuration so
    # that it's pushed to the end of the callback chain
    app.after_build do |builder|
      ::Middleman::S3Sync.sync(options) if options.after_build
    end

    options.build_dir ||= build_dir
  end
end

.s3_sync_optionsObject



36
37
38
# File 'lib/middleman-s3_sync/extension.rb', line 36

def s3_sync_options
  @options
end

.s3_sync_options=(options) ⇒ Object



40
41
42
# File 'lib/middleman-s3_sync/extension.rb', line 40

def s3_sync_options=(options)
  @options = options
end

.sync(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/middleman/s3_sync.rb', line 20

def sync(options)
  @app = ::Middleman::Application.server.inst

  self.s3_sync_options = options

  unless work_to_be_done?
    say_status "\nAll S3 files are up to date."
    return
  end

  say_status "\nReady to apply updates to #{s3_sync_options.bucket}."

  update_bucket_versioning

  ignore_resources
  create_resources
  update_resources
  delete_resources

  @app.run_hook :after_s3_sync, ignored: files_to_ignore.map(&:path),
                                created: files_to_create.map(&:path),
                                updated: files_to_update.map(&:path),
                                deleted: files_to_delete.map(&:path)
end