Class: Fog::Storage::HP::Directory
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::HP::Directory
show all
- Defined in:
- lib/fog/hp/models/storage/directory.rb
Instance Attribute Summary
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Model
#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
This class inherits a constructor from Fog::Model
Instance Method Details
#acl=(new_acl) ⇒ Object
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/fog/hp/models/storage/directory.rb', line 15
def acl=(new_acl)
if new_acl.nil?
new_acl = "private"
end
valid_acls = ['private', 'public-read', 'public-write', 'public-read-write']
unless valid_acls.include?(new_acl)
raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
end
@acl = new_acl
end
|
#cdn_enable=(new_cdn_enable) ⇒ Object
80
81
82
83
84
85
86
87
88
|
# File 'lib/fog/hp/models/storage/directory.rb', line 80
def cdn_enable=(new_cdn_enable)
@cdn_enable ||= false
if (!connection.cdn.nil? && connection.cdn.enabled?)
@cdn_enable = new_cdn_enable
else
@cdn_enable = false
end
end
|
#cdn_enabled? ⇒ Boolean
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/fog/hp/models/storage/directory.rb', line 90
def cdn_enabled?
if (!connection.cdn.nil? && connection.cdn.enabled?)
begin response = connection.cdn.head_container(key)
= response..fetch('X-Cdn-Enabled', nil)
if (!.nil? && == 'True')
@cdn_enable = true
else
@cdn_enable = false
end
rescue Fog::CDN::HP::NotFound => err
@cdn_enable = false
end
else
@cdn_enable = false
end
end
|
#cdn_public_url ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/fog/hp/models/storage/directory.rb', line 107
def cdn_public_url
requires :key
@cdn_public_url ||= begin
begin response = connection.cdn.head_container(key)
if response.['X-Cdn-Enabled'] == 'True'
if connection.hp_cdn_ssl == true
response..fetch('X-Cdn-Ssl-Uri', nil)
else
response..fetch('X-Cdn-Uri', nil)
end
end
rescue Fog::CDN::HP::NotFound => err
nil
end
end
end
|
#destroy ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/fog/hp/models/storage/directory.rb', line 26
def destroy
requires :key
connection.delete_container(key)
if cdn_enabled?
begin
connection.cdn.delete_container(key)
rescue Fog::CDN::HP::NotFound
end
end
true
rescue Excon::Errors::NotFound, Fog::Storage::HP::NotFound
false
end
|
#files ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/fog/hp/models/storage/directory.rb', line 42
def files
@files ||= begin
Fog::Storage::HP::Files.new(
:directory => self,
:connection => connection
)
end
end
|
#public=(new_public) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/fog/hp/models/storage/directory.rb', line 51
def public=(new_public)
if new_public
@acl = 'public-read'
else
@acl = 'private'
end
@public = new_public
end
|
#public? ⇒ Boolean
60
61
62
63
64
65
66
|
# File 'lib/fog/hp/models/storage/directory.rb', line 60
def public?
if @acl.nil?
false
else
@acl == 'public-read'
end
end
|
#public_url ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/fog/hp/models/storage/directory.rb', line 68
def public_url
requires :key
@public_url ||= begin
begin response = connection.head_container(key)
url = "#{connection.url}/#{Fog::HP.escape(key)}"
rescue Fog::Storage::HP::NotFound => err
nil
end
end
end
|
#save ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/fog/hp/models/storage/directory.rb', line 125
def save
requires :key
options = {}
if @acl
options.merge!(connection.(@acl))
end
connection.put_container(key, options)
if (!connection.cdn.nil? && connection.cdn.enabled?)
if @cdn_enable
begin response = connection.cdn.head_container(key)
connection.cdn.post_container(key, {'X-CDN-Enabled' => 'True'})
rescue Fog::CDN::HP::NotFound => err
connection.cdn.put_container(key)
end
else
begin response = connection.cdn.head_container(key)
connection.cdn.post_container(key, {'X-CDN-Enabled' => 'False'})
rescue Fog::CDN::HP::NotFound => err
end
end
end
true
end
|