Method: FakeS3::SortedObjectList#list
- Defined in:
- lib/fakes3/sorted_object_list.rb
#list(options) ⇒ Object
Return back a set of matches based on the passed in options
options:
:marker : a string to start the lexographical search (it is not included
in the result)
:max_keys : a maximum number of results :prefix : a string to filter the results by :delimiter : not supported yet
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fakes3/sorted_object_list.rb', line 58 def list() marker = [:marker] prefix = [:prefix] max_keys = [:max_keys] || 1000 delimiter = [:delimiter] ms = S3MatchSet.new marker_found = true pseudo = nil if marker marker_found = false if !@object_map[marker] pseudo = S3Object.new pseudo.name = marker @sorted_set << pseudo end end if delimiter if prefix base_prefix = prefix else base_prefix = "" end prefix_offset = base_prefix.length end count = 0 last_chunk = nil @sorted_set.each do |s3_object| if marker_found && (!prefix or s3_object.name.index(prefix) == 0) if delimiter name = s3_object.name remainder = name.slice(prefix_offset, name.length) chunks = remainder.split(delimiter, 2) if chunks.length > 1 if (last_chunk != chunks[0]) # "All of the keys rolled up in a common prefix count as # a single return when calculating the number of # returns. See MaxKeys." # (http://awsdocs.s3.amazonaws.com/S3/latest/s3-api.pdf) count += 1 if count <= max_keys ms.common_prefixes << base_prefix + chunks[0] + delimiter last_chunk = chunks[0] else is_truncated = true break end end # Continue to the next key, since this one has a # delimiter. next end end count += 1 if count <= max_keys ms.matches << s3_object else is_truncated = true break end end if marker and marker == s3_object.name marker_found = true end end if pseudo @sorted_set.delete(pseudo) end return ms end |