Class: FakeAWS::S3::ObjectCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fake_aws/s3/object_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ ObjectCollection

Returns a new instance of ObjectCollection.



9
10
11
12
13
14
# File 'lib/fake_aws/s3/object_collection.rb', line 9

def initialize(bucket)
  @bucket = bucket
  @objects = Hash.new do |h, key|
    h[key] = S3Object.new(bucket, key)
  end
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
# File 'lib/fake_aws/s3/object_collection.rb', line 16

def [](key)
  key = key.to_s
  @objects[key]
end

#delete_allObject



21
22
23
# File 'lib/fake_aws/s3/object_collection.rb', line 21

def delete_all
  @objects.clear
end

#delete_if(&block) ⇒ Object



27
28
29
# File 'lib/fake_aws/s3/object_collection.rb', line 27

def delete_if(&block)
  @objects.delete_if(&block)
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/fake_aws/s3/object_collection.rb', line 31

def each(&block)
  @objects.values.select(&:exists?).sort_by(&:key).each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fake_aws/s3/object_collection.rb', line 35

def empty?
  !@objects.values.any?(&:exists?)
end