Class: Nab::S3Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/nab/adapters/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeS3Adapter

Returns a new instance of S3Adapter.



7
8
9
10
11
# File 'lib/nab/adapters/s3.rb', line 7

def initialize
  AWS.config
  @write_adapter = FileWriter
  @strip_dirs = false
end

Instance Attribute Details

#strip_dirsObject

Returns the value of attribute strip_dirs.



5
6
7
# File 'lib/nab/adapters/s3.rb', line 5

def strip_dirs
  @strip_dirs
end

#write_adapterObject

Returns the value of attribute write_adapter.



5
6
7
# File 'lib/nab/adapters/s3.rb', line 5

def write_adapter
  @write_adapter
end

Instance Method Details

#get(uri, destination) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/nab/adapters/s3.rb', line 13

def get(uri,destination)
  bucket_name = uri.host
  s3          = AWS::S3.new
  bucket      = s3.buckets[bucket_name]
  asset       = bucket.objects[Util.path_from_uri(uri)]
  asset_name  = Util.path_from_uri(uri,strip_dirs)
  Nab::Log.info "Retrieving #{File.join(bucket_name,asset_name)}"
  store       = write_adapter.new(destination, asset_name)

  asset.read { |chunk| store.write chunk }
  store.close
end