Sha256: 597dba2e99d9aa1297882858176e0d4dad12119f9bbd220b11b27d157fdb5d4f

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require 'aws'
require 'vos/drivers/s3_vfs_storage'

module Vos
  module Drivers
    class S3
      attr_reader :connection, :bucket

      DEFAULT_OPTIONS = {
        # public: true
      }

      def initialize initialization_options, options = {}
        @initialization_options, @options = initialization_options, DEFAULT_OPTIONS.merge(options)
      end


      #
      # Establishing SSH channel
      #
      def open &block
        if block
          if connection
            block.call self
          else
            begin
              open
              block.call self
            ensure
              close
            end
          end
        else
          unless connection
            @connection = ::AWS::S3.new self.initialization_options.clone
            unless bucket = options[:bucket]
              raise("S3 bucket not provided (use Vos::Drivers::S3.new({initialization options ...}, {bucket: '<bucket_name>'}))!")
            end
            @bucket = @connection.buckets[bucket]
          end
        end
      end

      def close; end

      #
      # Vfs
      #
      include S3VfsStorage


      #
      # Miscellaneous
      #
      def inspect; "<#{self.class.name} #{initialization_options.inspect}, #{options.inspect}>" end
      alias_method :to_s, :inspect

      def _clear
        bucket.objects.each{|o| o.delete}
      end

      protected
        attr_reader :initialization_options, :options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vos-0.3.15 lib/vos/drivers/s3.rb
vos-0.3.14 lib/vos/drivers/s3.rb