Method: Octopress::Deploy::S3#pull

Defined in:
lib/octopress-deploy/s3.rb

#pullObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/octopress-deploy/s3.rb', line 48

def pull
  @bucket = @s3.buckets[@bucket_name]
  if !@bucket.exists?
    abort "Bucket not found: '#{@bucket_name}'. Check your configuration or create a bucket using: `octopress deploy add-bucket`"
  else
    puts "Syncing from S3 bucket: '#{@bucket_name}' to #{@pull_dir}."
    @bucket.objects.each do |object|
      path = File.join(@pull_dir, object.key)

      # Path is a directory, not a file
      if path =~ /\/$/ 
        FileUtils.mkdir_p(path) unless File.directory?(path)
      else
        dir = File.dirname(path)
        FileUtils.mkdir_p(dir) unless File.directory?(dir)
        File.open(path, 'w') { |f| f.write(object.read) }
      end
    end
  end
end