Class: Fog::OpenStack::Storage::Mock
- Inherits:
-
Object
- Object
- Fog::OpenStack::Storage::Mock
- Defined in:
- lib/fog/openstack/storage.rb,
lib/fog/openstack/storage/requests/public_url.rb,
lib/fog/openstack/storage/requests/put_object.rb
Class Method Summary collapse
Instance Method Summary collapse
- #change_account(account) ⇒ Object
- #data ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #put_object(container, object, data, options = {}, &block) ⇒ Object
- #reset_account_name ⇒ Object
- #reset_data ⇒ Object
Methods included from PublicUrl
Methods included from Utils
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fog/openstack/storage.rb', line 74 def initialize( = {}) require_mime_types @openstack_api_key = [:openstack_api_key] @openstack_username = [:openstack_username] @openstack_management_url = [:openstack_management_url] || 'http://example:8774/v2/AUTH_1234' @openstack_management_uri = URI.parse(@openstack_management_url) @path = @openstack_management_uri.path @path.sub!(%r{/$}, '') end |
Class Method Details
.data ⇒ Object
64 65 66 67 68 |
# File 'lib/fog/openstack/storage.rb', line 64 def self.data @data ||= Hash.new do |hash, key| hash[key] = {} end end |
.reset ⇒ Object
70 71 72 |
# File 'lib/fog/openstack/storage.rb', line 70 def self.reset @data = nil end |
Instance Method Details
#change_account(account) ⇒ Object
93 94 95 96 97 |
# File 'lib/fog/openstack/storage.rb', line 93 def change_account(account) @original_path ||= @path version_string = @original_path.split('/')[1] @path = "/#{version_string}/#{account}" end |
#data ⇒ Object
85 86 87 |
# File 'lib/fog/openstack/storage.rb', line 85 def data self.class.data[@openstack_username] end |
#put_object(container, object, data, options = {}, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fog/openstack/storage/requests/put_object.rb', line 43 def put_object(container, object, data, = {}, &block) dgst = Digest::MD5.new if block_given? Kernel.loop do chunk = yield break if chunk.empty? dgst.update chunk end elsif data.kind_of?(String) dgst.update data else dgst.file data end response = Excon::Response.new response.status = 201 response.body = '' response.headers = {'ETag' => dgst.hexdigest} response end |
#reset_account_name ⇒ Object
99 100 101 |
# File 'lib/fog/openstack/storage.rb', line 99 def reset_account_name @path = @original_path end |
#reset_data ⇒ Object
89 90 91 |
# File 'lib/fog/openstack/storage.rb', line 89 def reset_data self.class.data.delete(@openstack_username) end |