Class: Fog::Storage::HP::SharedFile

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/hp/models/storage/shared_file.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#bodyObject



21
22
23
24
25
26
27
# File 'lib/fog/hp/models/storage/shared_file.rb', line 21

def body
  attributes[:body] ||= if last_modified
    collection.get(identity).body
  else
    ''
  end
end

#body=(new_body) ⇒ Object



29
30
31
# File 'lib/fog/hp/models/storage/shared_file.rb', line 29

def body=(new_body)
  attributes[:body] = new_body
end

#destroyObject



33
34
35
36
37
38
39
40
# File 'lib/fog/hp/models/storage/shared_file.rb', line 33

def destroy
  requires :shared_directory, :key
  service.delete_shared_object(self.url)
  true
# throws exception Fog::HP::Errors::Forbidden if insufficient access
rescue Fog::Storage::HP::NotFound
  false
end

#save(options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fog/hp/models/storage/shared_file.rb', line 46

def save(options = {})
  requires :shared_directory, :key
  options['Content-Type'] = content_type if content_type
  data = service.put_shared_object(shared_directory.url, key, body, options)
  merge_attributes(data.headers)
  self.content_length = Fog::Storage.get_body_size(body)
  true
# throws exception Fog::HP::Errors::Forbidden if insufficient access
rescue Fog::Storage::HP::NotFound
  false
end

#shared_directoryObject



42
43
44
# File 'lib/fog/hp/models/storage/shared_file.rb', line 42

def shared_directory
  @shared_directory
end

#urlObject



17
18
19
# File 'lib/fog/hp/models/storage/shared_file.rb', line 17

def url
  "#{self.collection.shared_directory.url}/#{key}"
end