Class: RailsUploads::Storages::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_uploads/storages/local.rb

Instance Method Summary collapse

Constructor Details

#initialize(default) ⇒ Local



5
6
7
# File 'lib/rails_uploads/storages/local.rb', line 5

def initialize(default)
  @tmp = (Rails.env == 'test' and not default)
end

Instance Method Details

#delete(path) ⇒ Object



31
32
33
# File 'lib/rails_uploads/storages/local.rb', line 31

def delete(path)
  ::File.delete realpath(path)
end

#exists?(path) ⇒ Boolean



9
10
11
# File 'lib/rails_uploads/storages/local.rb', line 9

def exists?(path)
  ::File.exists? realpath(path)
end

#magick(source, output, upload) {|RailsUploads::Magick::Image.new(realpath(source), realpath(output))| ... } ⇒ Object

Yields:



35
36
37
38
# File 'lib/rails_uploads/storages/local.rb', line 35

def magick(source, output, upload)
  create_dir realpath(output)
  yield RailsUploads::Magick::Image.new(realpath(source), realpath(output))
end

#size(path) ⇒ Object



13
14
15
# File 'lib/rails_uploads/storages/local.rb', line 13

def size(path)
  ::File.size realpath(path)
end

#store(upload, path) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rails_uploads/storages/local.rb', line 21

def store(upload, path)
  create_dir realpath(path)
  upload.rewind # Hack to avoid empty files
  ::File.open(realpath(path), 'wb') do |file|
    while chunk = upload.read(16 * 1024)
      file.write(chunk)
    end
  end
end

#url(path) ⇒ Object



17
18
19
# File 'lib/rails_uploads/storages/local.rb', line 17

def url(path)
  ::File.join Rails.application.config.uploads.base_url, path
end