Class: Stacktor::Swift::V1::ContainerObject
Instance Attribute Summary
#client, #data
Instance Method Summary
collapse
#[], #[]=, #handle_data, #headers, #initialize, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Stacktor::Core::Resource
Instance Method Details
#container_name ⇒ Object
13
14
15
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 13
def container_name
data['container_name']
end
|
#content_length ⇒ Object
21
22
23
24
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 21
def content_length
bytes = data['bytes'] || ['Content-Length']
bytes ? bytes.to_i : nil
end
|
#content_type ⇒ Object
26
27
28
29
30
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 26
def content_type
type = data['content_type'] || ['Content-Type']
return nil if type.nil?
return type.split(";").first
end
|
#delete ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 89
def delete
result = @client.delete_object(container_name: self.container_name, object_name: self.name)
if result[:success]
return result
else
raise result[:body]
end
end
|
#etag ⇒ Object
17
18
19
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 17
def etag
data['hash'] || ['ETag']
end
|
#last_modified ⇒ Object
32
33
34
35
36
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 32
def last_modified
t = data['last_modified'] || ['Last-Modified']
return nil if t.nil?
return Time.parse(t)
end
|
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 38
def metadata
ret = {}
.each do |k,v|
h = k.downcase.strip
if h.start_with?("x-object-meta-")
mk = h.split('-').last
ret[mk] = v
end
end
return ret
end
|
#name ⇒ Object
9
10
11
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 9
def name
data['name']
end
|
#read ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 52
def read
result = @client.get_object_content(container_name: self.container_name, object_name: self.name)
if result[:success]
return result[:body]
else
raise result[:body]
end
end
|
#reload ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 80
def reload
result = @client.get_object_metadata(container_name: self.container_name, object_name: self.name)
if result[:success]
self.handle_data(result[:body], headers: result[:response])
else
raise result[:body]
end
end
|
#stream(&block) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 61
def stream(&block)
result = @client.get_object_content(container_name: self.container_name, object_name: self.name) do |bytes|
block.call(bytes)
end
if result[:success]
return result[:body]
else
raise result[:body]
end
end
|
#write_to_file(path) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/stacktor/swift/v1/container_object.rb', line 72
def write_to_file(path)
File.open(path, 'wb') do |fw|
self.stream do |bytes|
fw.write bytes
end
end
end
|