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



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

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

#body=(new_body) ⇒ Object



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

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

#content_typeObject



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

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

#destroyObject



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

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

#directoryObject



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

def directory
  @directory
end

#directory=(new_directory) ⇒ Object



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

def directory=(new_directory)
  @directory = new_directory
end

#public=(new_public) ⇒ Object



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

def public=(new_public)
  new_public
end

#public_urlObject



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

def public_url
  nil
end

#saveObject



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

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