Sha256: e4a1c6b1ca79e7b15690962c9012dda4b777c77573a17984da3354280b5005d2

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'builder'
require 'thread'
require 'rack_fake_s3/s3_object'
require 'rack_fake_s3/sorted_object_list'

module RackFakeS3
  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

5 entries across 5 versions & 1 rubygems

Version Path
rack_fake_s3-0.2.4 lib/rack_fake_s3/bucket.rb
rack_fake_s3-0.2.3 lib/rack_fake_s3/bucket.rb
rack_fake_s3-0.2.2 lib/rack_fake_s3/bucket.rb
rack_fake_s3-0.2.1 lib/rack_fake_s3/bucket.rb
rack_fake_s3-0.2.0 lib/rack_fake_s3/bucket.rb