Class: GyomuRuby::AmazonWebService::FileBucket::PoorMan

Inherits:
Object
  • Object
show all
Defined in:
lib/gyomu_ruby/amazon_web_service/file_bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ PoorMan

Returns a new instance of PoorMan.



27
28
29
30
31
# File 'lib/gyomu_ruby/amazon_web_service/file_bucket.rb', line 27

def initialize(bucket)
  @bucket = bucket
  path = Rails.root.join('tmp', @bucket)
  FileUtils.mkdir_p path unless FileTest.exist? path
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



25
26
27
# File 'lib/gyomu_ruby/amazon_web_service/file_bucket.rb', line 25

def bucket
  @bucket
end

Instance Method Details

#delete(key) ⇒ Object



41
42
43
# File 'lib/gyomu_ruby/amazon_web_service/file_bucket.rb', line 41

def delete(key)
  !!FileUtils.rm_r(Rails.root.join('tmp', @bucket, key))
end

#get(key) ⇒ Object



37
38
39
# File 'lib/gyomu_ruby/amazon_web_service/file_bucket.rb', line 37

def get(key)
  File.open(Rails.root.join('tmp', @bucket, key), 'r:BINARY') {|f| f.read }
end

#put(key, io) ⇒ Object



33
34
35
# File 'lib/gyomu_ruby/amazon_web_service/file_bucket.rb', line 33

def put(key, io)
  File.open(Rails.root.join('tmp', @bucket, key), 'w:BINARY') {|f| f.write(io.read)}
end