Sha256: e82fb01d6e4bba290ca48f610ce90605ad3fe6a076eee75b0a2ca1ef2d442a5b

Contents?: true

Size: 890 Bytes

Versions: 1

Compression:

Stored size: 890 Bytes

Contents

require 's3'
require 'massive_sitemap/writer/gzip_file'

module MassiveSitemap
  module Writer
    class S3 < MassiveSitemap::Writer::GzipFile

      def initialize(cfg, options = {})
        @service = ::S3::Service.new(cfg)
        @bucket  = @service.buckets.find(cfg[:bucket])
        super(options)
      end

      protected
      def close_stream(stream)
        @filename = filename
        super
        # upload to amazon
        # TODO what if fail??
        @bucket.objects.build(::File.basename(@filename)).tap do |object|
          object.content = ::File.open(@filename)
          object.save
        end
      end

      def load_stream_ids
        @bucket.objects.find_all.each do |object|
          if ::File.extname(object.key) == ::File.extname(filename)
            add_stream_id(object.key, object.last_modified)
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
massive_sitemap-writer-s3-0.0.1.rc2 lib/massive_sitemap/writer/s3.rb