Sha256: f490805c4e814d64fb35b257831731b1a57cd01caf40e6df3e61d68d511e2a42

Contents?: true

Size: 887 Bytes

Versions: 10

Compression:

Stored size: 887 Bytes

Contents

module Rake
  module DSL

    def cloud_cp(dir, options)
      # Done here to allow fog to be an optional dependency
      require 'fog'

      connection = Fog::Storage.new(options[:credentials])
      cd dir do
        upload_sub_dir(connection, '.', options[:bucket], options[:public] || false)
      end
    end

    def upload_sub_dir(connection, dir, bucket, is_public)
      is_public ||= false
      Dir["#{dir}/*"].each do |file|
        if File.directory? file
          upload_sub_dir(connection, file, bucket, is_public)
        else
          file_name = file.gsub("./", '')
          puts "Uploading: '#{file_name}'"
          directory = connection.directories.get(bucket)
          file = directory.files.create(
            :key    => file_name,
            :body   => IO.read(file),
            :public => is_public
          )
        end
      end
    end
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ggake-0.9.0 lib/ggake/cloud_cp.rb
ggake-0.8.0 lib/ggake/cloud_cp.rb
ggake-0.7.0 lib/ggake/cloud_cp.rb
ggake-0.6.0 lib/ggake/cloud_cp.rb
ggake-0.5.0 lib/ggake/cloud_cp.rb
ggake-0.4.1 lib/ggake/cloud_cp.rb
ggake-0.4.0 lib/ggake/cloud_cp.rb
ggake-0.3.1 lib/ggake/cloud_cp.rb
ggake-0.3.0 lib/ggake/cloud_cp.rb
ggake-0.2.0 lib/ggake/cloud_cp.rb