Class: Fog::Storage::External::File

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

Instance Method Summary collapse

Instance Method Details

#bodyObject



29
30
31
32
33
34
35
# File 'lib/fog/external/models/storage/file.rb', line 29

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

#body=(new_body) ⇒ Object



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

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

#content_typeObject



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

def content_type
  @content_type ||= begin
    unless (mime_types = ::MIME::Types.of(key)).empty?
      mime_types.first.content_type
    end
  end
end

#destroyObject



41
42
43
44
45
46
# File 'lib/fog/external/models/storage/file.rb', line 41

def destroy
  requires :key, :directory
  
  connection.remote.destroy_file(full_key)
  true
end

#directoryObject



13
14
15
# File 'lib/fog/external/models/storage/file.rb', line 13

def directory
  @directory
end

#directory=(new_directory) ⇒ Object



17
18
19
# File 'lib/fog/external/models/storage/file.rb', line 17

def directory=(new_directory)
  @directory = new_directory
end

#public=(new_public) ⇒ Object



48
49
50
# File 'lib/fog/external/models/storage/file.rb', line 48

def public=(new_public)
  new_public
end

#public_urlObject



52
53
54
# File 'lib/fog/external/models/storage/file.rb', line 52

def public_url
  nil
end

#saveObject



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

def save
  requires :body, :directory, :key
  
  if res = connection.remote.save_file(full_key, body)
    merge_attributes(
      :content_length => Fog::Storage.get_body_size(body),
      :last_modified  => res
    )
    true
  else
    false
  end
end