Class: Fog::Storage::Rackspace::Mock::MockContainer
- Inherits:
-
Object
- Object
- Fog::Storage::Rackspace::Mock::MockContainer
- Defined in:
- lib/fog/rackspace/storage.rb
Overview
An in-memory container for use with Rackspace storage mocks. Includes many ‘objects` mapped by (escaped) object name. Tracks container metadata.
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#add_object(name, data) ⇒ Object
Add a new MockObject to this container.
-
#bytes_used ⇒ Integer
Total sizes of all objects added to this container.
-
#empty? ⇒ Boolean
Determine if this container contains any MockObjects or not.
-
#initialize(service) ⇒ MockContainer
constructor
Create a new container.
-
#mock_object(name) ⇒ MockObject?
Access a MockObject within this container by (unescaped) name.
-
#mock_object!(name) ⇒ MockObject
Access a MockObject with a specific name, raising a ‘Fog::Storage::Rackspace::NotFound` exception if none are present.
-
#remove_object(name) ⇒ Object
Remove a MockObject from the container by name.
-
#to_headers ⇒ Hash<String, String>
Render the HTTP headers that would be associated with this container.
Constructor Details
#initialize(service) ⇒ MockContainer
Create a new container. Generally, you should call Rackspace::Storage#add_container instead.
131 132 133 134 |
# File 'lib/fog/rackspace/storage.rb', line 131 def initialize(service) @service = service @objects, @meta = {}, {} end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
127 128 129 |
# File 'lib/fog/rackspace/storage.rb', line 127 def @meta end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
127 128 129 |
# File 'lib/fog/rackspace/storage.rb', line 127 def objects @objects end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
127 128 129 |
# File 'lib/fog/rackspace/storage.rb', line 127 def service @service end |
Instance Method Details
#add_object(name, data) ⇒ Object
Add a new MockObject to this container. An existing object with the same name will be overwritten.
187 188 189 |
# File 'lib/fog/rackspace/storage.rb', line 187 def add_object(name, data) @objects[Fog::Rackspace.escape(name)] = MockObject.new(data, service) end |
#bytes_used ⇒ Integer
Total sizes of all objects added to this container.
147 148 149 |
# File 'lib/fog/rackspace/storage.rb', line 147 def bytes_used @objects.values.map { |o| o.bytes_used }.inject(0) { |a, b| a + b } end |
#empty? ⇒ Boolean
Determine if this container contains any MockObjects or not.
139 140 141 |
# File 'lib/fog/rackspace/storage.rb', line 139 def empty? @objects.empty? end |
#mock_object(name) ⇒ MockObject?
Access a MockObject within this container by (unescaped) name.
168 169 170 |
# File 'lib/fog/rackspace/storage.rb', line 168 def mock_object(name) @objects[Fog::Rackspace.escape(name)] end |
#mock_object!(name) ⇒ MockObject
Access a MockObject with a specific name, raising a ‘Fog::Storage::Rackspace::NotFound` exception if none are present.
178 179 180 |
# File 'lib/fog/rackspace/storage.rb', line 178 def mock_object!(name) mock_object(name) or raise Fog::Storage::Rackspace::NotFound.new end |