Class: Vos::Drivers::S3

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

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(options = {}) ⇒ S3

Returns a new instance of S3.



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

def initialize options = {}
  options = options.clone
  @bucket_name = options.delete(:bucket) || raise("S3 bucket not provided!")
  @acl = options.delete(:acl) || :public_read
  @options = options
end

Instance Attribute Details

#boxObject

Returns the value of attribute box.



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

def box
  @box
end

#bucketObject (readonly)

Returns the value of attribute bucket.



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

def bucket
  @bucket
end

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#_clearObject



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

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

#closeObject



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

def close; end

#inspectObject Also known as: to_s

Miscellaneous



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

def inspect; "https://#{bucket_name}.s3.amazonaws.com" 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
# 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.options.clone
      @bucket = @connection.buckets[bucket_name]
    end
  end
end