Class: SwiftStorage::Node
- Inherits:
-
Object
- Object
- SwiftStorage::Node
show all
- Includes:
- Headers, Utils
- Defined in:
- lib/swift_storage/node.rb
Constant Summary
Constants included
from Headers
Headers::ACCOUNT_TEMP_URL_KEY, Headers::AUTH_KEY, Headers::AUTH_TOKEN, Headers::AUTH_USER, Headers::CACHE_CONTROL, Headers::CONNECTION, Headers::CONTAINER_READ, Headers::CONTAINER_WRITE, Headers::CONTENT_DISPOSITION, Headers::CONTENT_TYPE, Headers::DELETE_AFTER, Headers::DELETE_AT, Headers::DESTINATION, Headers::EXPIRES, Headers::OBJECT_MANIFEST, Headers::PROXY_CONNECTION, Headers::STORAGE_TOKEN, Headers::STORAGE_URL
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Utils
#hmac, #sig_to_hex, #struct
Constructor Details
#initialize(parent, name = nil) ⇒ Node
Returns a new instance of Node.
7
8
9
10
|
# File 'lib/swift_storage/node.rb', line 7
def initialize(parent, name=nil)
@parent = parent
@name = name
end
|
Instance Attribute Details
Returns the value of attribute name.
5
6
7
|
# File 'lib/swift_storage/node.rb', line 5
def name
@name
end
|
Returns the value of attribute parent.
5
6
7
|
# File 'lib/swift_storage/node.rb', line 5
def parent
@parent
end
|
Instance Method Details
#clear_cache ⇒ Object
79
80
81
82
|
# File 'lib/swift_storage/node.rb', line 79
def clear_cache
@headers = nil
@metadata = nil
end
|
91
92
93
|
# File 'lib/swift_storage/node.rb', line 91
def delete
request(relative_path, :method => :delete)
end
|
#exists? ⇒ Boolean
84
85
86
87
88
89
|
# File 'lib/swift_storage/node.rb', line 84
def exists?
request(relative_path, :method => :head)
true
rescue SwiftStorage::Errors::NotFoundError
false
end
|
#get_lines(path, prefix: nil) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/swift_storage/node.rb', line 32
def get_lines(path, prefix: nil)
= {'Accept' => 'text/plain'}
response = request(path, :headers => , :params => {:prefix => prefix})
body = response.body
if body.nil? || body.empty?
[]
else
body.lines.map(&:strip)
end
end
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/swift_storage/node.rb', line 51
def
return @headers if @headers
response ||= request(relative_path, :method => :head)
h = {}
metadata = h[:metadata] = {}
response.to_hash.each_pair do |k,v|
if k =~ /^X-#{self.class.}-Meta-?(.+)/i
k = $1
t = metadata
elsif k =~ /^X-#{self.class.}-?(.+)/i
k = $1
t = h
else
t = h
end
k = k.downcase.gsub(/\W/, '_')
v = v.first if v.respond_to?(:to_ary)
t[k] = v
end
@headers = struct(h)
end
|
75
76
77
|
# File 'lib/swift_storage/node.rb', line 75
def metadata
@metadata ||= struct(.metadata)
end
|
#relative_path ⇒ Object
47
48
49
|
# File 'lib/swift_storage/node.rb', line 47
def relative_path
raise NotImplemented
end
|
#request(*args) ⇒ Object
12
13
14
|
# File 'lib/swift_storage/node.rb', line 12
def request(*args)
service.request(*args)
end
|
Returns the service for this node
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/swift_storage/node.rb', line 21
def service
unless defined?(@service)
p = parent
while p && !(SwiftStorage::Service === p)
p = p.parent
end
@service = p
end
@service
end
|
43
44
45
|
# File 'lib/swift_storage/node.rb', line 43
def to_s
"#<#{self.class.name} #{name}>"
end
|