Class: FakeS3::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_s3/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Bucket

Returns a new instance of Bucket.



5
6
7
8
# File 'lib/fake_s3/bucket.rb', line 5

def initialize(name)
  @name = name
  clear
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/fake_s3/bucket.rb', line 3

def name
  @name
end

Instance Method Details

#clearObject



10
11
12
# File 'lib/fake_s3/bucket.rb', line 10

def clear
  @objects = {}
end

#keys_to_contentsObject



22
23
24
25
26
# File 'lib/fake_s3/bucket.rb', line 22

def keys_to_contents
  @objects.map_to_hash do |key, obj|
    [key, obj.get.body.read]
  end
end

#move_to(src, dest) ⇒ Object



28
29
30
# File 'lib/fake_s3/bucket.rb', line 28

def move_to(src, dest)
  @objects[dest.key] = @objects.delete(src.key)
end

#object(key) ⇒ Object



18
19
20
# File 'lib/fake_s3/bucket.rb', line 18

def object(key)
  @objects[key] ||= FakeS3::Object.new(self, key, nil)
end

#objects(_ = {}) ⇒ Object



14
15
16
# File 'lib/fake_s3/bucket.rb', line 14

def objects(_ = {})
  @objects.keep_if(&:exists?)
end