Class: Fog::Storage::Akamai::Mock
- Inherits:
-
Object
- Object
- Fog::Storage::Akamai::Mock
show all
- Includes:
- Helpers, Initializer
- Defined in:
- lib/fog/akamai/storage.rb,
lib/fog/akamai/requests/storage/du.rb,
lib/fog/akamai/requests/storage/dir.rb,
lib/fog/akamai/requests/storage/stat.rb,
lib/fog/akamai/requests/storage/mkdir.rb,
lib/fog/akamai/requests/storage/mtime.rb,
lib/fog/akamai/requests/storage/rmdir.rb,
lib/fog/akamai/requests/storage/delete.rb,
lib/fog/akamai/requests/storage/rename.rb,
lib/fog/akamai/requests/storage/upload.rb,
lib/fog/akamai/requests/storage/symlink.rb,
lib/fog/akamai/requests/storage/download.rb
Class Method Summary
collapse
Instance Method Summary
collapse
included, #init
Methods included from Helpers
#format_path, #path_and_body_guard, #path_guard
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
71
72
73
|
# File 'lib/fog/akamai/storage.rb', line 71
def initialize(options = {})
init(options)
end
|
Class Method Details
.data ⇒ Object
67
68
69
|
# File 'lib/fog/akamai/storage.rb', line 67
def self.data
@data ||= {}
end
|
Instance Method Details
#data ⇒ Object
75
76
77
|
# File 'lib/fog/akamai/storage.rb', line 75
def data
self.class.data
end
|
#delete(path) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/fog/akamai/requests/storage/delete.rb', line 21
def delete(path)
path_guard(path)
if remove_file(Pathname.new(format_path(path)))
Excon::Response.new(status: 200)
else
fail(Excon::Errors::NotFound, '404 Not Found')
end
end
|
#dir(path = '') ⇒ Object
32
33
34
35
|
# File 'lib/fog/akamai/requests/storage/dir.rb', line 32
def dir(path = '')
key = format_path(path)
data.key?(key) ? Excon::Response.new(status: 200, body: data[key]) : fail(Excon::Errors::NotFound, '404 Not Found')
end
|
#download(path) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/fog/akamai/requests/storage/download.rb', line 20
def download(path)
path_guard(path)
formatted_path = format_path(path)
fail(Excon::Errors::NotFound, '404 Not Found') unless data.key?(formatted_path) && data[formatted_path].key?(:body)
Excon::Response.new(status: 200, body: data[formatted_path][:body])
end
|
#du(path) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/fog/akamai/requests/storage/du.rb', line 27
def du(path)
path_guard(path)
key = format_path(path)
directory = data[key]
if directory
Excon::Response.new(status: 200, body: { directory: key, files: directory[:files].count.to_s, bytes: directory[:directories].count.to_s })
else
fail(Excon::Errors::NotFound, '404 Not Found')
end
end
|
#mkdir(path) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/akamai/requests/storage/mkdir.rb', line 22
def mkdir(path)
path_guard(path)
path = Pathname.new(format_path(path))
last_path_basename = ''
path.ascend do |parent|
break if parent.nil?
key = parent.to_s
update_data(key, last_path_basename)
last_path_basename = parent.basename.to_s
end
Excon::Response.new(headers: { 'Status' => 200 })
end
|
#mtime(path, mtime = DateTime.now.to_time.to_i) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/fog/akamai/requests/storage/mtime.rb', line 22
def mtime(path, mtime = DateTime.now.to_time.to_i)
path_guard(path)
pathname = Pathname.new(format_path(path))
file = get_file(pathname)
if file
file['mtime'] = mtime.to_s
Excon::Response.new(status: 200)
else
fail(Excon::Errors::NotFound, '404 Not Found')
end
end
|
#rename(source, destination) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/akamai/requests/storage/rename.rb', line 24
def rename(source, destination)
path_guard(source)
path_guard(destination)
source_pathname = Pathname.new(format_path(source))
destination_pathname = Pathname.new(format_path(destination))
if rename_file(source_pathname, destination_pathname)
move_file(source_pathname, destination_pathname)
Excon::Response.new(status: 200)
else
fail(Excon::Errors::NotFound, '404 Not Found')
end
end
|
#reset_data ⇒ Object
79
80
81
|
# File 'lib/fog/akamai/storage.rb', line 79
def reset_data
self.class.data.clear
end
|
#rmdir(path) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/akamai/requests/storage/rmdir.rb', line 19
def rmdir(path)
path_guard(path)
formatted_path = format_path(path)
dir = data[formatted_path]
if empty?(dir)
data.delete(formatted_path)
Excon::Response.new(status: 200)
else
fail(Excon::Errors::Conflict, 'Not a empty directory')
end
end
|
#stat(path) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fog/akamai/requests/storage/stat.rb', line 36
def stat(path)
path_guard(path)
path = Pathname.new(format_path(path))
key = path.split.first.to_s
response = Excon::Response.new(status: get_status(key, path.basename.to_s), body: get_body(key))
fail(Excon::Errors::NotFound, '404 Not Found') if response.status == 404
response
end
|
#upload(path, body) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/fog/akamai/requests/storage/upload.rb', line 26
def upload(path, body)
path_and_body_guard(path, body)
path = Pathname(path)
dir = path.split.first.to_s
mkdir(dir)
add_file(dir, path, body)
Excon::Response.new(status: 200)
end
|