Sha256: a27f34c8d90c9a23507737a625025e8f394a8c67744e8e45944d63399788f575

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

module MultiSync
  module Extensions
    class AssetSync
      class << self
        def asset_sync_yml_exists?
          ::Rails.root.nil? ? false : File.exist?(asset_sync_yml_path)
        end

        def asset_sync_yml_path
          ::Rails.root.join('config', 'asset_sync.yml')
        end

        def asset_sync_yml
          @asset_sync_yml ||= YAML.load_file(asset_sync_yml_path)[MultiSync.env]
        end

        def check_and_migrate
          return unless self.asset_sync_yml_exists?
          MultiSync.source(:rails,
            type: :manifest,
            source_dir: MultiSync::Extensions::Rails.source_dir
          )

          MultiSync.target(:assets,
            type: asset_sync_yml['fog_provider'],
            target_dir: asset_sync_yml['fog_directory'],
            destination_dir: MultiSync::Extensions::Rails.destination_dir,
            credentials: {
              region: asset_sync_yml['region'],
              aws_access_key_id: asset_sync_yml['aws_access_key_id'],
              aws_secret_access_key: asset_sync_yml['aws_secret_access_key'],
              path_style: asset_sync_yml['path_style']
            }
          )

          MultiSync.delete_abandoned_files = asset_sync_yml['existing_remote_files'] == 'delete'
          MultiSync.run_on_build = asset_sync_yml['run_on_precompile']

          MultiSync.info 'AssetSync YAML file found, migrating options...' if MultiSync.run_on_build
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
multi_sync-0.0.4 lib/multi_sync/extensions/rails/asset_sync.rb
multi_sync-0.0.3 lib/multi_sync/extensions/rails/asset_sync.rb
multi_sync-0.0.2 lib/multi_sync/extensions/rails/asset_sync.rb