Class: Fog::Storage::OpenStack::Mock

Inherits:
Object
  • Object
show all
Includes:
PublicUrl, Utils
Defined in:
lib/fog/storage/openstack.rb,
lib/fog/storage/openstack/requests/public_url.rb,
lib/fog/storage/openstack/requests/put_object.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PublicUrl

#public_url

Methods included from Utils

#require_mime_types

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fog/storage/openstack.rb', line 73

def initialize(options = {})
  require_mime_types
  @openstack_api_key = options[:openstack_api_key]
  @openstack_username = options[:openstack_username]
  @openstack_management_url = options[:openstack_management_url] || 'http://example:8774/v2/AUTH_1234'

  @openstack_management_uri = URI.parse(@openstack_management_url)

  @host   = @openstack_management_uri.host
  @path   = @openstack_management_uri.path
  @path.sub!(%r{/$}, '')
  @port   = @openstack_management_uri.port
  @scheme = @openstack_management_uri.scheme
end

Class Method Details

.dataObject



63
64
65
66
67
# File 'lib/fog/storage/openstack.rb', line 63

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {}
  end
end

.resetObject



69
70
71
# File 'lib/fog/storage/openstack.rb', line 69

def self.reset
  @data = nil
end

Instance Method Details

#change_account(account) ⇒ Object



96
97
98
99
100
# File 'lib/fog/storage/openstack.rb', line 96

def ()
  @original_path ||= @path
  version_string = @original_path.split('/')[1]
  @path = "/#{version_string}/#{}"
end

#dataObject



88
89
90
# File 'lib/fog/storage/openstack.rb', line 88

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/storage/openstack/requests/put_object.rb', line 43

def put_object(container, object, data, options = {}, &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_nameObject



102
103
104
# File 'lib/fog/storage/openstack.rb', line 102

def 
  @path = @original_path
end

#reset_dataObject



92
93
94
# File 'lib/fog/storage/openstack.rb', line 92

def reset_data
  self.class.data.delete(@openstack_username)
end