fog/fog — Issue #584: AWS::Files `each` method yields incorrect results
Author: kylefox
Created: 2011-11-02 18:07:10+00:00
State: open

The custom `each` method for `Fog::Storage::AWS::Files` disregards any filtering applied by calling Array methods such as `reject!` and `select!`

Assume S3 bucket has 3 files:

* index.html
* app.js
* styles.css

The result is a bit confusing:

files = bucket.files.all

files.reject! {|f| f.key == 'index.html'}
files.length # => Returns 2

count = 0
files.each {|f| count += 1}
count # => Returns 3

I'm not sure if this is a bug or intended behavior, but I thought I'd post it anyway. Either way it's _confusing_ and deserves some attention, either with a bugfix or documentation note. (I didn't submit a patch/docs because I wasn't sure if this is the way `each` is supposed to work in this case).

My vote is to either make `Files#each` behave as expected for an Array (preferred), or to _not_ have `Fog::Collection` inherit from Array in the first place.