Sha256: a5ba6a6b4dc7d4c4a5292f26ae304b23b73141b3326c0878f3918dd935d2b965

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

require 'builder'
require 'thread'
require 'fakes3/s3_object'
require 'fakes3/sorted_object_list'

module FakeS3
  class Bucket
    attr_accessor :name,:creation_date,:objects

    def initialize(name,creation_date,objects)
      @name = name
      @creation_date = creation_date
      @objects = SortedObjectList.new
      objects.each do |obj|
        @objects.add(obj)
      end
      @mutex = Mutex.new
    end

    def find(object_name)
      @mutex.synchronize do
        @objects.find(object_name)
      end
    end

    def add(object)
      # Unfortunately have to synchronize here since the our SortedObjectList
      # not thread safe. Probably can get finer granularity if performance is
      # important
      @mutex.synchronize do
        @objects.add(object)
      end
    end

    def remove(object)
      @mutex.synchronize do
        @objects.remove(object)
      end
    end

    def query_for_range(options)
      marker = options[:marker]
      prefix = options[:prefix]
      max_keys = options[:max_keys] || 1000
      delimiter = options[:delimiter]

      match_set = nil
      @mutex.synchronize do
        match_set = @objects.list(options)
      end

      bq = BucketQuery.new
      bq.bucket = self
      bq.marker = marker
      bq.prefix = prefix
      bq.max_keys = max_keys
      bq.delimiter = delimiter
      bq.matches = match_set.matches
      bq.is_truncated = match_set.is_truncated
      return bq
    end

  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
fakes3-0.1.7 lib/fakes3/bucket.rb
fakes3-0.1.6.1 lib/fakes3/bucket.rb
fakes3-0.1.6.0 lib/fakes3/bucket.rb
fakes3-0.1.5.2 lib/fakes3/bucket.rb
amione-fakes3-0.1.5.1 lib/fakes3/bucket.rb
fakes3-0.1.5 lib/fakes3/bucket.rb
fakes3-0.1.4 lib/fakes3/bucket.rb
fakes3-0.1.3 lib/fakes3/bucket.rb
fakes3-0.1.2 lib/fakes3/bucket.rb