Class: UzuUzu::Wrapper::S3

Inherits:
Object show all
Defined in:
lib/uzuuzu-core/wrapper/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ S3

Returns a new instance of S3.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/uzuuzu-core/wrapper/s3.rb', line 15

def initialize(env=nil)
  if env.nil?
  return
  end
  @env = env.dup
  @buckets_env = @env['buckets'].dup
  @access_key = @env['access_key'] || @env[:access_key] ||''
  @secret_key = @env['secret_key'] || @env[:secret_key] ||''
  
 params = {}
 params[:server] = @env['server'] unless @env['server'] .blank?
 params[:port] = @env['port'] unless @env['port'] .blank?
 params[:protocol] = @env['protocol'] unless @env['protocol'] .blank?
 params[:logger] = ::UzuUzu.logger
  @s3 = ::RightAws::S3.new(@access_key, @secret_key, params)
  @buckets = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/uzuuzu-core/wrapper/s3.rb', line 36

def method_missing(name, *args)
  name = name.to_s
  if @buckets_env[name].nil?
    return nil
  end
  if  @buckets[name].nil?
    params = {}
    params[:location] = @buckets_env[name]['location'] unless @buckets_env[name]['location'].blank?
    params = nil if params.blank?
    @buckets[name] = @s3.bucket(@buckets_env[name]['name'], true, params)
  end
  @buckets[name]
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



10
11
12
# File 'lib/uzuuzu-core/wrapper/s3.rb', line 10

def buckets
  @buckets
end

#s3Object (readonly)

Returns the value of attribute s3.



8
9
10
# File 'lib/uzuuzu-core/wrapper/s3.rb', line 8

def s3
  @s3
end