Class: Fog::Storage::HP::SharedFiles

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

Instance Attribute Summary

Attributes inherited from Collection

#service

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #destroy, #initialize, #inspect, #load, model, #model, #reload, #table, #to_json

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::Collection

Instance Method Details

#allObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/hp/models/storage/shared_files.rb', line 14

def all
  requires :shared_directory
  parent = shared_directory.collection.get(shared_directory.url)
  if parent
    load(parent.files.map {|file| file.attributes})
  else
    nil
  end
# throws exception Fog::HP::Errors::Forbidden if insufficient access
rescue Fog::Storage::HP::NotFound
  nil
end

#get(key, &block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/hp/models/storage/shared_files.rb', line 27

def get(key, &block)
  requires :shared_directory
  shared_object_url = "#{shared_directory.url}/#{key}"
  data = service.get_shared_object(shared_object_url, &block)
  file_data = data.headers.merge({
    :body => data.body,
    :key  => key
  })
  new(file_data)
# throws exception Fog::HP::Errors::Forbidden if insufficient access
rescue Fog::Storage::HP::NotFound
  nil
end

#head(key) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fog/hp/models/storage/shared_files.rb', line 41

def head(key)
  requires :shared_directory
  shared_object_url = "#{shared_directory.url}/#{key}"
  data = service.head_shared_object(shared_object_url)
  file_data = data.headers.merge({
    :body => '',
    :key => key
  })
  new(file_data)
# throws exception Fog::HP::Errors::Forbidden if insufficient access
rescue Fog::Storage::HP::NotFound
  nil
end

#new(attributes = {}) ⇒ Object



55
56
57
58
# File 'lib/fog/hp/models/storage/shared_files.rb', line 55

def new(attributes = {})
  requires :shared_directory
  super({ :shared_directory => shared_directory }.merge!(attributes))
end