Sha256: 9dcb3e73fd94829082ff6b52244650c300a41f98956844f59774d4a422690e0f

Contents?: true

Size: 994 Bytes

Versions: 4

Compression:

Stored size: 994 Bytes

Contents

require 'json'

module Sdbport
  class Domain
    class Export

      def initialize(args)
        @name       = args[:name]
        @logger     = args[:logger]
        @access_key = args[:access_key]
        @secret_key = args[:secret_key]
        @region     = args[:region]
      end

      def export(output)
        @logger.info "Export #{@name} in #{@region} to #{output}"
        file = File.open(output, 'w')
        export_domain.each do |item| 
          file.write convert_to_string item
          file.write "\n"
        end
        return true if file.close.nil?
      end

      private

      def sdb
        @sdb ||= AWS::SimpleDB.new :access_key => @access_key,
                                   :secret_key => @secret_key,
                                   :region     => @region
      end

      def export_domain
        sdb.select_and_follow_tokens "select * from `#{@name}`"
      end

      def convert_to_string(item)
        item.to_json
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sdbport-0.3.0 lib/sdbport/domain/export.rb
sdbport-0.2.1 lib/sdbport/domain/export.rb
sdbport-0.2.0 lib/sdbport/domain/export.rb
sdbport-0.1.1 lib/sdbport/domain/export.rb