class Naifa::Plugins::S3

Constants

DEFAULT_SETTINGS

Public Class Methods

build_sync_command(from_bucket, to_bucket, sync_options=[]) click to toggle source
# File lib/naifa/plugins/s3.rb, line 44
def self.build_sync_command(from_bucket, to_bucket, sync_options=[])
  command = "aws s3 sync #{from_bucket} #{to_bucket}"
  command << " #{sync_options.join(' ')}" if sync_options.present?
  command
end
sync(options={}) click to toggle source
# File lib/naifa/plugins/s3.rb, line 12
def self.sync(options={})
  options ||= {}

  sync_settings = options[:sync]
  environments_settings = options[:environments]

  if sync_settings.blank? ||
    sync_settings[:origin].blank? ||
    sync_settings[:destination].blank?

    raise Thor::Error, "Sync settings are not defined"
  end

  origin = sync_settings[:origin]
  destination = sync_settings[:destination]

  if environments_settings.blank? ||
    environments_settings[origin].blank? || environments_settings[origin][:bucket].blank? ||
    environments_settings[destination].blank? || environments_settings[destination][:bucket].blank?

    raise Thor::Error, "Sync environments not set"
  end

  command = build_sync_command(
              environments_settings[origin][:bucket],
              environments_settings[destination][:bucket],
              sync_settings.fetch(:sync_options, [])
            )

  Kernel.system(command)
end