Class: Fog::OpenStack::Storage::File

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

Instance Attribute Summary collapse

Attributes inherited from Model

#project

Instance Method Summary collapse

Methods inherited from Model

#create, #update

Constructor Details

#initialize(new_attributes = {}) ⇒ File

Returns a new instance of File.



37
38
39
40
# File 'lib/fog/openstack/storage/models/file.rb', line 37

def initialize(new_attributes = {})
  super
  @dirty = if last_modified then false else true end
end

Instance Attribute Details

#content_encodingObject

When you create an object or update its metadata, you can optionally set the Content-Encoding metadata. This metadata enables you to indicate that the object content is compressed without losing the identity of the underlying media type (Content-Type) of the file, such as a video.



35
# File 'lib/fog/openstack/storage/models/file.rb', line 35

attribute :content_encoding, :aliases => 'Content-Encoding'

#delete_afterInteger

A number of seconds representing how long from now this object will be automatically deleted.

Returns:

  • (Integer)

    the number of seconds until this object will be automatically deleted

See Also:



28
# File 'lib/fog/openstack/storage/models/file.rb', line 28

attribute :delete_after, :aliases => ['X-Delete-After']

#delete_atInteger

A Unix Epoch Timestamp, in integer form, representing the time when this object will be automatically deleted.

Returns:

  • (Integer)

    the unix epoch timestamp of when this object will be automatically deleted

See Also:



22
# File 'lib/fog/openstack/storage/models/file.rb', line 22

attribute :delete_at, :aliases => ['X-Delete-At']

#directoryObject

Returns the value of attribute directory.



55
56
57
# File 'lib/fog/openstack/storage/models/file.rb', line 55

def directory
  @directory
end

Instance Method Details

#bodyObject



42
43
44
45
46
47
48
# File 'lib/fog/openstack/storage/models/file.rb', line 42

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

#body=(new_body) ⇒ Object



50
51
52
53
# File 'lib/fog/openstack/storage/models/file.rb', line 50

def body=(new_body)
  attributes[:body] = new_body
  @dirty = true
end

#copy(target_directory_key, target_file_key, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/openstack/storage/models/file.rb', line 57

def copy(target_directory_key, target_file_key, options = {})
  requires :directory, :key
  options['Content-Type'] ||= content_type if content_type
  options['Access-Control-Allow-Origin'] ||= access_control_allow_origin if access_control_allow_origin
  options['Origin'] ||= origin if origin
  options['Content-Encoding'] ||= content_encoding if content_encoding
  service.copy_object(directory.key, key, target_directory_key, target_file_key, options)
  target_directory = service.directories.new(:key => target_directory_key)
  target_directory.files.get(target_file_key)
end

#destroyObject



68
69
70
71
72
73
# File 'lib/fog/openstack/storage/models/file.rb', line 68

def destroy
  requires :directory, :key
  service.delete_object(directory.key, key)
  @dirty = true
  true
end

#metadataObject



75
76
77
# File 'lib/fog/openstack/storage/models/file.rb', line 75

def 
  attributes[:metadata] ||= 
end

#owner=(new_owner) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/fog/openstack/storage/models/file.rb', line 79

def owner=(new_owner)
  if new_owner
    attributes[:owner] = {
      :display_name => new_owner['DisplayName'],
      :id           => new_owner['ID']
    }
  end
end

#public=(new_public) ⇒ Object



88
89
90
# File 'lib/fog/openstack/storage/models/file.rb', line 88

def public=(new_public)
  new_public
end

#public_urlObject



105
106
107
108
# File 'lib/fog/openstack/storage/models/file.rb', line 105

def public_url
  requires :key
  collection.get_url(key)
end

#save(options = {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fog/openstack/storage/models/file.rb', line 110

def save(options = {})
  requires :directory, :key
  options['Cache-Control'] = cache_control if cache_control
  options['Content-Type'] = content_type if content_type
  options['Content-Disposition'] = content_disposition if content_disposition
  options['Access-Control-Allow-Origin'] = access_control_allow_origin if access_control_allow_origin
  options['Origin'] = origin if origin
  options['X-Delete-At'] = delete_at if delete_at
  options['X-Delete-After'] = delete_after if delete_after
  options['Content-Encoding'] = content_encoding if content_encoding
  options.merge!()

  if not @dirty
    data = service.post_object(directory.key, key, options)
  else
    requires :body
    data = service.put_object(directory.key, key, body, options)
    self.content_length = Fog::Storage.get_body_size(body)
    self.content_type ||= Fog::Storage.get_content_type(body)
  end
  update_attributes_from(data)
  

  true
end

#url(expires, options = {}) ⇒ String

Get a url for file.

required attributes: key

Parameters:

  • expires (String)

    number of seconds (since 1970-01-01 00:00) before url expires

  • options (Hash) (defaults to: {})

Returns:

  • (String)

    url



100
101
102
103
# File 'lib/fog/openstack/storage/models/file.rb', line 100

def url(expires, options = {})
  requires :directory, :key
  service.create_temp_url(directory.key, key, expires, "GET", options)
end