Class: Vos::Drivers::S3

Inherits:
Object
  • Object
show all
Includes:
S3VfsStorage
Defined in:
lib/vos/drivers/s3.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  # public: true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from S3VfsStorage

#attributes, #create_dir, #delete_dir, #delete_file, #each_entry, #local?, #read_file, #set_attributes, #tmp, #write_file

Constructor Details

#initialize(initialization_options, options = {}) ⇒ S3

Returns a new instance of S3.



13
14
15
# File 'lib/vos/drivers/s3.rb', line 13

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

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



7
8
9
# File 'lib/vos/drivers/s3.rb', line 7

def bucket
  @bucket
end

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/vos/drivers/s3.rb', line 7

def connection
  @connection
end

Instance Method Details

#_clearObject



58
59
60
# File 'lib/vos/drivers/s3.rb', line 58

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

#closeObject



44
# File 'lib/vos/drivers/s3.rb', line 44

def close; end

#inspectObject Also known as: to_s

Miscellaneous



55
# File 'lib/vos/drivers/s3.rb', line 55

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

#open(&block) ⇒ Object

Establishing SSH channel



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vos/drivers/s3.rb', line 21

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