Sha256: e6daa699904ddc2bfb7b848ea5e446a0064a871b60656a35264474d26d8607bc

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

class TransferablePicture

  attr_accessor :asset, :container

  def initialize asset, container
    @asset = asset
    @container = container
  end

  def process
    copy_file
    recreate_versions!
  end

  private

  def asset_host
    @asset_host ||= CarrierWave::Uploader::Base.asset_host
  end

  def filename
    @filename ||= asset.data_file_name
  end

  def old_path
    @old_path ||= 'system/ckeditor_assets/pictures/' + filename
  end

  def new_path
    @new_path ||= "assets/#{asset.id}/" + filename
  end

  def copy_file
    if container.object_exists?(old_path)
        if !container.object_exists?(new_path)
        container.object(old_path).copy(name: new_path)
        # asset.remote_data_url = asset_host + '/' + new_path
        puts "#{filename} copied from #{old_path} to #{new_path}"
      else
        puts "#{new_path} destination already exists"
      end
    else
      puts "#{old_path} does not exists"
    end
  end

  def recreate_versions!
    puts "#{filename} versions recreated" if asset.data.recreate_versions!
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
georgia-0.7.6 lib/georgia/assets/transferable_picture.rb
georgia-0.7.5 lib/georgia/assets/transferable_picture.rb
georgia-0.7.4 lib/georgia/assets/transferable_picture.rb
georgia-0.7.3 lib/georgia/assets/transferable_picture.rb
georgia-0.7.2 lib/georgia/assets/transferable_picture.rb
georgia-0.7.1 lib/georgia/assets/transferable_picture.rb
georgia-0.7.0 lib/georgia/assets/transferable_picture.rb