Class: FakeS3::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/fakes3/bucket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, creation_date, objects) ⇒ Bucket

Returns a new instance of Bucket.



10
11
12
13
14
15
16
17
18
# File 'lib/fakes3/bucket.rb', line 10

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

Instance Attribute Details

#creation_dateObject

Returns the value of attribute creation_date.



8
9
10
# File 'lib/fakes3/bucket.rb', line 8

def creation_date
  @creation_date
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/fakes3/bucket.rb', line 8

def name
  @name
end

#objectsObject

Returns the value of attribute objects.



8
9
10
# File 'lib/fakes3/bucket.rb', line 8

def objects
  @objects
end

Instance Method Details

#add(object) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/fakes3/bucket.rb', line 26

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

#find(object_name) ⇒ Object



20
21
22
23
24
# File 'lib/fakes3/bucket.rb', line 20

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

#query_for_range(options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fakes3/bucket.rb', line 41

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

#remove(object) ⇒ Object



35
36
37
38
39
# File 'lib/fakes3/bucket.rb', line 35

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