Class: Fog::Storage::Atmos::File
- Inherits:
-
Model
- Object
- Model
- Fog::Storage::Atmos::File
- Defined in:
- lib/fog/atmos/models/storage/file.rb
Instance Method Summary collapse
- #body ⇒ Object
- #body=(new_body) ⇒ Object
- #copy(target_directory_key, target_file_key, options = {}) ⇒ Object
- #destroy ⇒ Object
- #directory ⇒ Object
- #file_size ⇒ Object
- #meta_data ⇒ Object
- #public=(new_public) ⇒ Object
-
#public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) ⇒ Object
By default, expire in 5 years.
- #save(options = {}) ⇒ Object
Instance Method Details
#body ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/fog/atmos/models/storage/file.rb', line 16 def body attributes[:body] ||= if objectid collection.get(identity).body else '' end end |
#body=(new_body) ⇒ Object
24 25 26 |
# File 'lib/fog/atmos/models/storage/file.rb', line 24 def body=(new_body) attributes[:body] = new_body end |
#copy(target_directory_key, target_file_key, options = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/fog/atmos/models/storage/file.rb', line 32 def copy(target_directory_key, target_file_key, ={}) target_directory = service.directories.new(:key => target_directory_key) target_directory.files.create( :key => target_file_key, :body => body ) end |
#destroy ⇒ Object
40 41 42 43 44 |
# File 'lib/fog/atmos/models/storage/file.rb', line 40 def destroy requires :directory, :key service.delete_namespace([directory.key, key].join('/')) true end |
#directory ⇒ Object
28 29 30 |
# File 'lib/fog/atmos/models/storage/file.rb', line 28 def directory @directory end |
#file_size ⇒ Object
51 52 53 54 |
# File 'lib/fog/atmos/models/storage/file.rb', line 51 def file_size data = .headers["x-emc-meta"].match(/size=\d+/).to_s.gsub(/size=/,"") end |
#meta_data ⇒ Object
46 47 48 49 |
# File 'lib/fog/atmos/models/storage/file.rb', line 46 def requires :directory, :key service.get_namespace([directory.key, key].join('/') + "?metadata/system") end |
#public=(new_public) ⇒ Object
56 57 58 |
# File 'lib/fog/atmos/models/storage/file.rb', line 56 def public=(new_public) # NOOP - we don't need to flag files as public, getting the public URL for a file handles it. end |
#public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) ⇒ Object
By default, expire in 5 years
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/atmos/models/storage/file.rb', line 61 def public_url(expires = (Time.now + 5 * 365 * 24 * 60 * 60)) file = directory.files.head(key) self.objectid = if file && file.to_s.strip != "" then file.attributes['x-emc-meta'].scan(/objectid=(\w+),/).flatten[0] else nil end if self.objectid && self.objectid.to_s.strip != "" klass = service.ssl? ? URI::HTTPS : URI::HTTP uri = klass.build(:host => service.host, :port => service.port.to_i, :path => "/rest/objects/#{self.objectid}" ) sb = "GET\n" sb += uri.path.downcase + "\n" sb += service.uid + "\n" sb += String(expires.to_i()) signature = service.sign( sb ) uri.query = "uid=#{CGI::escape(service.uid)}&expires=#{expires.to_i()}&signature=#{CGI::escape(signature)}" uri.to_s else nil end end |
#save(options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fog/atmos/models/storage/file.rb', line 81 def save( = {}) requires :body, :directory, :key directory.kind_of?(Directory) ? ns = directory.key : ns = directory ns += key [:headers] ||= {} [:headers]['Content-Type'] = content_type if content_type [:body] = body begin data = service.post_namespace(ns, ) self.objectid = data.headers['location'].split('/')[-1] rescue => error if error. =~ /The resource you are trying to create already exists./ data = service.put_namespace(ns, ) else raise error end end # merge_attributes(data.headers) true end |